CreateNamespace creates a namespace.
( ctx context.Context, crudClient client.Client, name string, opts ...client.CreateOption, )
| 131 | |
| 132 | // CreateNamespace creates a namespace. |
| 133 | func CreateNamespace( |
| 134 | ctx context.Context, |
| 135 | crudClient client.Client, |
| 136 | name string, |
| 137 | opts ...client.CreateOption, |
| 138 | ) error { |
| 139 | // Exit immediately if the name is empty |
| 140 | if name == "" { |
| 141 | return errors.New("cannot create namespace with empty name") |
| 142 | } |
| 143 | |
| 144 | u := &unstructured.Unstructured{} |
| 145 | u.SetName(name) |
| 146 | u.SetGroupVersionKind(schema.GroupVersionKind{ |
| 147 | Group: "", |
| 148 | Version: "v1", |
| 149 | Kind: "Namespace", |
| 150 | }) |
| 151 | _, err := objects.Create(ctx, crudClient, u, opts...) |
| 152 | return err |
| 153 | } |
| 154 | |
| 155 | // EnsureNamespace checks for the presence of a namespace, and if it does not |
| 156 | // exist, creates it |
no test coverage detected