set-namespace

command module
v0.4.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 6, 2022 License: Apache-2.0 Imports: 3 Imported by: 0

README

set-namespace

Overview

The set-namespace function replaces the input KRM resources' namespace fields.

Usage

Replace namespaces are commonly used in the following scenarios:

  • distinguish resources by environment. For example, you can update all resources under kpt package "prod" to namespace "prod", and another resources under kpt package "dev" to namespace "dev".
  • distinguish resources by teams or users. For example, you can "copy" and "create" a new set of resources by simply replacing the resources namespace to a different value.
Target KRM resources

This function not only update the namespace scoped resources' metadata.namespace or Namespace object's metadata.name, but handle some special resource types. See the full targeting resources below:

  • This function updates all namespace-scoped KRM resources metadata.namespace fields. We determine whether a custom KRM resource is namespace scoped by checking if it has metadata.namespace set.
  • This function updates RoleBinding and ClusterRoleBinding resources subjects element whose kind is ServiceAccount and the subject's namespace is set.
  • This function updates CustomResourceDefinition (CRD) spec/conversion/webhook/clientConfig/service/namespace field if the field is set.
  • This function updates APIService spec/service/namespace field if the field is set.
  • This function updates the KRM resources annotation config.kubernetes.io/depends-on if this annotation contains the namespace that shows up in other resources' namespace.
FunctionConfig

FunctionConfig is used to configure the set-namespace function behavior. It itself is a KRM resource which can be either a ConfigMap object or a custom SetNamespace object.

ConfigMap as functionConfig

apiVersion: v1
kind: ConfigMap
data:
  namespace: newNamespace # required

SetNamespace as functionConfig

apiVersion: fn.kpt.dev/v1alpha1
kind: SetNamespace
namespace: newNamespace # required

The package-context.yaml as functionConfig. This convention file is auto-generated by kpt pkg get --for-deploy or kpt pkg init

apiVersion: v1
kind: ConfigMap
metadata:
  name: kptfile.kpt.dev
  annotations:
    config.kubernetes.io/local-config: "true"
data:
  name: newNamespace # required, update all namespace fields to "newNamespace"
DependsOn annotation

DependsOn annotation is a kpt feature. This function updates the namespace segment in a depends-on annotation if the namespace matches the Namespace object or namespaceMatcher field.

Documentation

Overview

Copyright 2022 Google LLC

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Directories

Path Synopsis
Code generated by "mdtogo"; DO NOT EDIT.
Code generated by "mdtogo"; DO NOT EDIT.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL