Skip to content

Commit

Permalink
k8s: Add ability to specify namespace metadata
Browse files Browse the repository at this point in the history
This commit adds the ability to add labels or annotations to a newly
created namespace. This commit itself does not contain any changes in
functional behavior, the ability to add annotations will be used in a
subsequent commit.

Signed-off-by: Sebastian Wicki <[email protected]>
  • Loading branch information
gandro committed Jun 1, 2023
1 parent a217310 commit 5c1ec2b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
6 changes: 4 additions & 2 deletions connectivity/check/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,8 @@ func (ct *ConnectivityTest) deploy(ctx context.Context) error {
_, err := ct.clients.src.GetNamespace(ctx, ct.params.TestNamespace, metav1.GetOptions{})
if err != nil {
ct.Logf("✨ [%s] Creating namespace %s for connectivity check...", ct.clients.src.ClusterName(), ct.params.TestNamespace)
_, err = ct.clients.src.CreateNamespace(ctx, ct.params.TestNamespace, metav1.CreateOptions{})
meta := metav1.ObjectMeta{Name: ct.params.TestNamespace}
_, err = ct.clients.src.CreateNamespace(ctx, meta, metav1.CreateOptions{})
if err != nil {
return fmt.Errorf("unable to create namespace %s: %s", ct.params.TestNamespace, err)
}
Expand Down Expand Up @@ -583,7 +584,8 @@ func (ct *ConnectivityTest) deploy(ctx context.Context) error {
_, err = ct.clients.dst.GetNamespace(ctx, ct.params.TestNamespace, metav1.GetOptions{})
if err != nil {
ct.Logf("✨ [%s] Creating namespace %s for connectivity check...", ct.clients.dst.ClusterName(), ct.params.TestNamespace)
_, err = ct.clients.dst.CreateNamespace(ctx, ct.params.TestNamespace, metav1.CreateOptions{})
meta := metav1.ObjectMeta{Name: ct.params.TestNamespace}
_, err = ct.clients.src.CreateNamespace(ctx, meta, metav1.CreateOptions{})
if err != nil {
return fmt.Errorf("unable to create namespace %s: %s", ct.params.TestNamespace, err)
}
Expand Down
4 changes: 2 additions & 2 deletions install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ type k8sInstallerImplementation interface {
PatchDeployment(ctx context.Context, namespace, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions) (*appsv1.Deployment, error)
CheckDeploymentStatus(ctx context.Context, namespace, deployment string) error
DeleteNamespace(ctx context.Context, namespace string, opts metav1.DeleteOptions) error
CreateNamespace(ctx context.Context, namespace string, opts metav1.CreateOptions) (*corev1.Namespace, error)
CreateNamespace(ctx context.Context, meta metav1.ObjectMeta, opts metav1.CreateOptions) (*corev1.Namespace, error)
GetNamespace(ctx context.Context, namespace string, options metav1.GetOptions) (*corev1.Namespace, error)
ListPods(ctx context.Context, namespace string, options metav1.ListOptions) (*corev1.PodList, error)
DeletePod(ctx context.Context, namespace, name string, options metav1.DeleteOptions) error
Expand Down Expand Up @@ -870,7 +870,7 @@ func (k *K8sInstaller) Install(ctx context.Context) error {

secretsNamespace := k.getSecretNamespace()
if len(secretsNamespace) != 0 {
if _, err := k.client.CreateNamespace(ctx, secretsNamespace, metav1.CreateOptions{}); err != nil {
if _, err := k.client.CreateNamespace(ctx, metav1.ObjectMeta{Name: secretsNamespace}, metav1.CreateOptions{}); err != nil {
return err
}
k.pushRollbackStep(func(ctx context.Context) {
Expand Down
4 changes: 2 additions & 2 deletions k8s/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,8 @@ func (c *Client) CheckDeploymentStatus(ctx context.Context, namespace, deploymen
return nil
}

func (c *Client) CreateNamespace(ctx context.Context, namespace string, opts metav1.CreateOptions) (*corev1.Namespace, error) {
return c.Clientset.CoreV1().Namespaces().Create(ctx, &corev1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: namespace}}, opts)
func (c *Client) CreateNamespace(ctx context.Context, meta metav1.ObjectMeta, opts metav1.CreateOptions) (*corev1.Namespace, error) {
return c.Clientset.CoreV1().Namespaces().Create(ctx, &corev1.Namespace{ObjectMeta: meta}, opts)
}

func (c *Client) GetNamespace(ctx context.Context, namespace string, options metav1.GetOptions) (*corev1.Namespace, error) {
Expand Down

0 comments on commit 5c1ec2b

Please sign in to comment.