Skip to content

Commit f344bb3

Browse files
committed
feat: Support creating namespace with metadata on remote cluster
1 parent 4e8ab02 commit f344bb3

File tree

1 file changed

+23
-0
lines changed
  • pkg/handlers/generic/lifecycle/utils

1 file changed

+23
-0
lines changed

pkg/handlers/generic/lifecycle/utils/utils.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,29 @@ func EnsureNamespaceWithName(ctx context.Context, c ctrlclient.Client, name stri
108108
return EnsureNamespace(ctx, c, ns)
109109
}
110110

111+
// EnsureNamespaceWithMetadata will create the namespace with the specified name,
112+
// labels, and/or annotations, if it does not exist.
113+
func EnsureNamespaceWithMetadata(ctx context.Context,
114+
c ctrlclient.Client,
115+
name string,
116+
labels,
117+
annotations map[string]string,
118+
) error {
119+
ns := &corev1.Namespace{
120+
TypeMeta: metav1.TypeMeta{
121+
APIVersion: corev1.SchemeGroupVersion.String(),
122+
Kind: "Namespace",
123+
},
124+
ObjectMeta: metav1.ObjectMeta{
125+
Name: name,
126+
Annotations: annotations,
127+
Labels: labels,
128+
},
129+
}
130+
131+
return EnsureNamespace(ctx, c, ns)
132+
}
133+
111134
// EnsureNamespace will create the namespace if it does not exist.
112135
func EnsureNamespace(ctx context.Context, c ctrlclient.Client, ns *corev1.Namespace) error {
113136
if ns.TypeMeta.APIVersion == "" {

0 commit comments

Comments
 (0)