From 892438ee41acf80b552d872f6c395db553c7f6a3 Mon Sep 17 00:00:00 2001 From: Mike Borozdin Date: Fri, 28 May 2021 21:59:33 -0700 Subject: [PATCH 1/9] wip first stab --- package-examples/kustomize-pkg/README.md | 44 ++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 package-examples/kustomize-pkg/README.md diff --git a/package-examples/kustomize-pkg/README.md b/package-examples/kustomize-pkg/README.md new file mode 100644 index 0000000000..59857509ee --- /dev/null +++ b/package-examples/kustomize-pkg/README.md @@ -0,0 +1,44 @@ +# package-name + +This is a simple package that shows how kpt can be used to replace +remote bases in kustomize. + +## Steps + +1. [Fetch the package](#fetch-the-package) +2. [View the package contents](#view-the-package-contents) +3. [Configure functions](#configure-functions) +4. [Render the declared values](#render-the-declared-values) +5. [Apply the package](#apply-the-package) + +### Fetch the package + +Get the example package on to local using `kpt pkg get` + +```shell +$ kpt pkg get https://github.com/GoogleContainerTools/kpt.git/package-examples/kustomize-pkg + +fetching package /package-examples/kustomize-pkg from https://github.com/GoogleContainerTools/kpt to kustomize-pkg +``` + +### View the package contents + +List the package contents in a tree structure. + +```shell +$ kpt pkg tree kustomize-pkg/ + + +``` + +### Run kustomize build + +Since this package is using + +### Render the declared values + +This step should describe the process and exact steps to render the declared values. + +### Apply the package + +This step should describe the process and exact commands needed to deploy the resources to a live cluster. From 92bd84524ed71a20aa18478e1e13204fb24e0617 Mon Sep 17 00:00:00 2001 From: Mike Borozdin Date: Fri, 28 May 2021 21:59:49 -0700 Subject: [PATCH 2/9] rebase of next --- package-examples/helloworld-kustomize/Kptfile | 9 --- .../helloworld-kustomize/README.md | 74 ------------------- .../resources/deploy.yaml | 41 ---------- .../resources/service.yaml | 32 -------- package-examples/kustomize-pkg/Kptfile | 6 ++ .../kustomize-pkg/bases/nginx/Kptfile | 21 ++++++ .../bases/nginx/deployment.yaml} | 22 ++++-- .../bases/nginx/kustomization.yaml | 4 + .../bases/nginx/svc.yaml} | 22 +++--- .../overlays/dev/kustomization.yaml | 11 +++ .../overlays/dev/pass-patch.yaml | 12 +++ .../overlays/prod/kustomization.yaml | 11 +++ .../overlays/prod/pass-patch.yaml | 12 +++ 13 files changed, 104 insertions(+), 173 deletions(-) delete mode 100644 package-examples/helloworld-kustomize/Kptfile delete mode 100644 package-examples/helloworld-kustomize/README.md delete mode 100644 package-examples/helloworld-kustomize/resources/deploy.yaml delete mode 100644 package-examples/helloworld-kustomize/resources/service.yaml create mode 100644 package-examples/kustomize-pkg/Kptfile create mode 100644 package-examples/kustomize-pkg/bases/nginx/Kptfile rename package-examples/{helloworld-kustomize/patches/patch.yaml => kustomize-pkg/bases/nginx/deployment.yaml} (68%) create mode 100644 package-examples/kustomize-pkg/bases/nginx/kustomization.yaml rename package-examples/{helloworld-kustomize/kustomization.yaml => kustomize-pkg/bases/nginx/svc.yaml} (71%) create mode 100644 package-examples/kustomize-pkg/overlays/dev/kustomization.yaml create mode 100644 package-examples/kustomize-pkg/overlays/dev/pass-patch.yaml create mode 100644 package-examples/kustomize-pkg/overlays/prod/kustomization.yaml create mode 100644 package-examples/kustomize-pkg/overlays/prod/pass-patch.yaml diff --git a/package-examples/helloworld-kustomize/Kptfile b/package-examples/helloworld-kustomize/Kptfile deleted file mode 100644 index b81d9d2dab..0000000000 --- a/package-examples/helloworld-kustomize/Kptfile +++ /dev/null @@ -1,9 +0,0 @@ -apiVersion: kpt.dev/v1alpha2 -kind: Kptfile -metadata: - name: helloworld-kustomize -pipeline: - mutators: - - image: gcr.io/kpt-fn/apply-setters:unstable - configMap: - target: foobar diff --git a/package-examples/helloworld-kustomize/README.md b/package-examples/helloworld-kustomize/README.md deleted file mode 100644 index 3b0a8fc752..0000000000 --- a/package-examples/helloworld-kustomize/README.md +++ /dev/null @@ -1,74 +0,0 @@ -# helloworld-kustomize - -This is an example of a kpt package that has a kustomize -patch in it. - -## Steps - -1. [Fetch the package](#fetch-the-package) -2. [View the package contents](#view-the-package-contents) -3. [Configure functions](#configure-functions) -4. [Render the declared values](#render-the-declared-values) -5. [Apply the package](#apply-the-package) - -### Fetch the package - -Get the example package on to local using `kpt pkg get` - -```shell -$ kpt pkg get https://github.com/GoogleContainerTools/kpt.git/package-examples/helloworld-kustomize - -fetching package /package-examples/helloworld-kustomize from https://github.com/GoogleContainerTools/kpt to helloworld-kustomize -``` - -### View the package contents - -List the package contents in a tree structure. - -```shell -$ kpt pkg tree helloworld-kustomize/ - -Package "helloworld-kustomize" -├── [Kptfile] Kptfile helloworld-kustomize -├── patches -│ └── [patch.yaml] Deployment helloworld-gke -└── resources - ├── [deploy.yaml] Deployment helloworld-gke - └── [service.yaml] Service helloworld-gke -``` - -### Configure functions - -The package contains a function pipeline in the `Kptfile` which has -one `apply-setters` function. The `apply-setters` function allows you to -set a simple value throughout the package configuration. In this case the -value of the setter goes into the `patch.yaml`. You can set the target -environment variable to a value different of your choice (different -than `foobar`) - -```yaml -pipeline: - mutators: - - image: gcr.io/kpt-fn/apply-setters:unstable - configMap: - target: foobar -``` - -### Render the declared values - -Render the changes in the hydration pipeline by using `kpt fn render` command: - -```shell -$ kpt fn render helloworld-kustomize/ -``` - -### Apply the package - -Since this is a kustomize example we will be using `kubectl -k`: - -```shell -$ kubectl apply -k helloworld-kustomize - -service/helloworld-gke created -deployment.apps/helloworld-gke created -``` \ No newline at end of file diff --git a/package-examples/helloworld-kustomize/resources/deploy.yaml b/package-examples/helloworld-kustomize/resources/deploy.yaml deleted file mode 100644 index 76d7fb5af1..0000000000 --- a/package-examples/helloworld-kustomize/resources/deploy.yaml +++ /dev/null @@ -1,41 +0,0 @@ -# Copyright 2021 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. - -# This file configures the hello-world app which serves public web traffic. -apiVersion: apps/v1 -kind: Deployment -metadata: - name: helloworld-gke - labels: - app: hello - version: "0.1.0" -spec: - replicas: 5 - selector: - matchLabels: - app: hello - template: - metadata: - labels: - app: hello - spec: - containers: - - name: helloworld-gke - image: gcr.io/kpt-dev/helloworld-gke:0.3.0 - ports: - - name: http - containerPort: 80 - env: - - name: PORT - value: "80" diff --git a/package-examples/helloworld-kustomize/resources/service.yaml b/package-examples/helloworld-kustomize/resources/service.yaml deleted file mode 100644 index d9e9bd25cd..0000000000 --- a/package-examples/helloworld-kustomize/resources/service.yaml +++ /dev/null @@ -1,32 +0,0 @@ -# Copyright 2019 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. - -# The hello service provides a load-balancing proxy over the hello-app -# pods. By specifying the type as a 'LoadBalancer', Kubernetes Engine will -# create an external HTTP load balancer. -apiVersion: v1 -kind: Service -metadata: - name: helloworld-gke - labels: - app: hello - version: '0.1.0' -spec: - type: LoadBalancer - selector: - app: hello - ports: - - protocol: TCP - port: 80 - targetPort: http diff --git a/package-examples/kustomize-pkg/Kptfile b/package-examples/kustomize-pkg/Kptfile new file mode 100644 index 0000000000..b83f877595 --- /dev/null +++ b/package-examples/kustomize-pkg/Kptfile @@ -0,0 +1,6 @@ +apiVersion: kpt.dev/v1alpha2 +kind: Kptfile +metadata: + name: kustomize-pkg +info: + description: kustomize kpt package diff --git a/package-examples/kustomize-pkg/bases/nginx/Kptfile b/package-examples/kustomize-pkg/bases/nginx/Kptfile new file mode 100644 index 0000000000..4f6f589975 --- /dev/null +++ b/package-examples/kustomize-pkg/bases/nginx/Kptfile @@ -0,0 +1,21 @@ +apiVersion: kpt.dev/v1alpha2 +kind: Kptfile +metadata: + name: nginx +upstream: + type: git + git: + repo: https://github.com/GoogleContainerTools/kpt + directory: package-examples/nginx + ref: v0.2 + updateStrategy: resource-merge +upstreamLock: + type: git + git: + repo: https://github.com/GoogleContainerTools/kpt + directory: package-examples/nginx + ref: package-examples/nginx/v0.2 + commit: 4d2aa98b45ddee4b5fa45fbca16f2ff887de9efb +pipeline: + validators: + - image: gcr.io/kpt-fn/kubeval:v0.1 diff --git a/package-examples/helloworld-kustomize/patches/patch.yaml b/package-examples/kustomize-pkg/bases/nginx/deployment.yaml similarity index 68% rename from package-examples/helloworld-kustomize/patches/patch.yaml rename to package-examples/kustomize-pkg/bases/nginx/deployment.yaml index 4881d1d56d..128253405a 100644 --- a/package-examples/helloworld-kustomize/patches/patch.yaml +++ b/package-examples/kustomize-pkg/bases/nginx/deployment.yaml @@ -1,4 +1,4 @@ -# Copyright 2019 Google LLC +# Copyright 2021 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -11,16 +11,22 @@ # 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. - apiVersion: apps/v1 kind: Deployment -metadata: - name: helloworld-gke +metadata: # kpt-merge: /my-nginx + name: my-nginx spec: + replicas: 3 + selector: + matchLabels: + app: nginx template: + metadata: + labels: + app: nginx spec: containers: - - name: helloworld-gke - env: - - name: TARGET - value: 'changeme!' # kpt-set: ${target} + - name: nginx + image: nginx:1.14.1 + ports: + - containerPort: 80 diff --git a/package-examples/kustomize-pkg/bases/nginx/kustomization.yaml b/package-examples/kustomize-pkg/bases/nginx/kustomization.yaml new file mode 100644 index 0000000000..9be463c890 --- /dev/null +++ b/package-examples/kustomize-pkg/bases/nginx/kustomization.yaml @@ -0,0 +1,4 @@ +resources: +- deployment.yaml +- svc.yaml +- Kptfile \ No newline at end of file diff --git a/package-examples/helloworld-kustomize/kustomization.yaml b/package-examples/kustomize-pkg/bases/nginx/svc.yaml similarity index 71% rename from package-examples/helloworld-kustomize/kustomization.yaml rename to package-examples/kustomize-pkg/bases/nginx/svc.yaml index 74ac02ff6f..aed47e94bf 100644 --- a/package-examples/helloworld-kustomize/kustomization.yaml +++ b/package-examples/kustomize-pkg/bases/nginx/svc.yaml @@ -1,4 +1,4 @@ -# Copyright 2019 Google LLC +# Copyright 2021 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -11,11 +11,15 @@ # 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. - -commonLabels: - app: hello -resources: -- resources/deploy.yaml -- resources/service.yaml -patchesStrategicMerge: -- patches/patch.yaml +apiVersion: v1 +kind: Service +metadata: # kpt-merge: /my-nginx-svc + name: my-nginx-svc + labels: + app: nginx +spec: + type: LoadBalancer + selector: + app: nginx + ports: + - port: 80 diff --git a/package-examples/kustomize-pkg/overlays/dev/kustomization.yaml b/package-examples/kustomize-pkg/overlays/dev/kustomization.yaml new file mode 100644 index 0000000000..a2719c35d3 --- /dev/null +++ b/package-examples/kustomize-pkg/overlays/dev/kustomization.yaml @@ -0,0 +1,11 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +resources: +- ../../bases/nginx +patches: +- path: pass-patch.yaml + target: + kind: Deployment +commonLabels: + environ: dev +namePrefix: dev- diff --git a/package-examples/kustomize-pkg/overlays/dev/pass-patch.yaml b/package-examples/kustomize-pkg/overlays/dev/pass-patch.yaml new file mode 100644 index 0000000000..f9e9e0b668 --- /dev/null +++ b/package-examples/kustomize-pkg/overlays/dev/pass-patch.yaml @@ -0,0 +1,12 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: not-important +spec: + replicas: 1 + template: + spec: + containers: + - name: nginx + ports: + - containerPort: 80 diff --git a/package-examples/kustomize-pkg/overlays/prod/kustomization.yaml b/package-examples/kustomize-pkg/overlays/prod/kustomization.yaml new file mode 100644 index 0000000000..7191afb0aa --- /dev/null +++ b/package-examples/kustomize-pkg/overlays/prod/kustomization.yaml @@ -0,0 +1,11 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +resources: +- ../../bases/nginx +patches: +- path: pass-patch.yaml + target: + kind: Deployment +commonLabels: + environ: prod +namePrefix: prod- diff --git a/package-examples/kustomize-pkg/overlays/prod/pass-patch.yaml b/package-examples/kustomize-pkg/overlays/prod/pass-patch.yaml new file mode 100644 index 0000000000..c40e855eb6 --- /dev/null +++ b/package-examples/kustomize-pkg/overlays/prod/pass-patch.yaml @@ -0,0 +1,12 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: not-important +spec: + replicas: 6 + template: + spec: + containers: + - name: nginx + ports: + - containerPort: 443 From 00f83bdeb4c284813b7b1aaf1632b2b37aee11cd Mon Sep 17 00:00:00 2001 From: Mike Borozdin Date: Sat, 29 May 2021 08:38:01 -0700 Subject: [PATCH 3/9] updates to the kustomize files --- package-examples/kustomize-pkg/README.md | 118 ++++++++++++++++-- .../overlays/dev/kustomization.yaml | 14 +++ .../overlays/dev/pass-patch.yaml | 16 ++- .../overlays/prod/kustomization.yaml | 14 +++ .../overlays/prod/pass-patch.yaml | 16 ++- 5 files changed, 164 insertions(+), 14 deletions(-) diff --git a/package-examples/kustomize-pkg/README.md b/package-examples/kustomize-pkg/README.md index 59857509ee..16bb3dc44b 100644 --- a/package-examples/kustomize-pkg/README.md +++ b/package-examples/kustomize-pkg/README.md @@ -1,19 +1,18 @@ -# package-name +# kustomize-pkg -This is a simple package that shows how kpt can be used to replace -remote bases in kustomize. +This is a simple package that shows how kpt packages can be used instead of remote bases in kustomize. That allows you to take advantage of kpt's rebase and local, in-place edits. ## Steps 1. [Fetch the package](#fetch-the-package) 2. [View the package contents](#view-the-package-contents) -3. [Configure functions](#configure-functions) -4. [Render the declared values](#render-the-declared-values) +3. [kustomize the config](#kustomize-the-config) +4. [Render the kustomization](#render-the-kustomization) 5. [Apply the package](#apply-the-package) ### Fetch the package -Get the example package on to local using `kpt pkg get` +Get the example package on to local using `kpt pkg get`. Note that this package is for the example, wihin that package we are also fetch an nginx sub-package which is an alternative to having a remote base. ```shell $ kpt pkg get https://github.com/GoogleContainerTools/kpt.git/package-examples/kustomize-pkg @@ -21,6 +20,7 @@ $ kpt pkg get https://github.com/GoogleContainerTools/kpt.git/package-examples/k fetching package /package-examples/kustomize-pkg from https://github.com/GoogleContainerTools/kpt to kustomize-pkg ``` + ### View the package contents List the package contents in a tree structure. @@ -28,17 +28,111 @@ List the package contents in a tree structure. ```shell $ kpt pkg tree kustomize-pkg/ - +PKG: kustomize-pkg +├── [Kptfile] Kptfile kustomize-pkg +├── PKG: nginx +│ ├── [Kptfile] Kptfile nginx +│ ├── [deployment.yaml] Deployment my-nginx +│ └── [svc.yaml] Service my-nginx-svc +├── dev +│ ├── [kustomization.yaml] Kustomization +│ └── [pass-patch.yaml] Deployment deployment-patch +└── prod + ├── [kustomization.yaml] Kustomization + └── [pass-patch.yaml] Deployment deployment-patch ``` -### Run kustomize build +### kustomize the config + +We recommend that you keep the kustomize instructions to rendering only such as adding a namespace, transforming or applying a patch. The second you mix kpt packages and remote bases you will be missing out on a big advantage of having a guaranteed stable base. + +You can edit the patches and kustomize files we have created in the overlay folders. -Since this package is using +```yaml +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +resources: +- ../../bases/nginx +patches: +- path: pass-patch.yaml + target: + kind: Deployment +commonLabels: + environ: dev +namePrefix: dev- +``` + +### Render the kustomization -### Render the declared values +You can see the final configuration that the patch is going to render. The major difference between this and in place edit is that you can't just go to the file and look at it in isolation, you need to run `kustomize build` and examine the final results. -This step should describe the process and exact steps to render the declared values. +```shell +$ kustomize build + +apiVersion: v1 +kind: Service +metadata: + labels: + app: nginx + environ: dev + name: dev-my-nginx-svc +spec: + ports: + - port: 80 + selector: + app: nginx + environ: dev + type: LoadBalancer +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + labels: + environ: dev + name: dev-my-nginx +spec: + replicas: 1 + selector: + matchLabels: + app: nginx + environ: dev + template: + metadata: + labels: + app: nginx + environ: dev + spec: + containers: + - image: nginx:1.14.1 + name: nginx + ports: + - containerPort: 80 +--- +apiVersion: kpt.dev/v1alpha2 +kind: Kptfile +metadata: + labels: + environ: dev + name: dev-nginx +pipeline: + validators: + - image: gcr.io/kpt-fn/kubeval:v0.1 +upstream: + git: + directory: package-examples/nginx + ref: v0.2 + repo: https://github.com/GoogleContainerTools/kpt + type: git + updateStrategy: resource-merge +upstreamLock: + git: + commit: 4d2aa98b45ddee4b5fa45fbca16f2ff887de9efb + directory: package-examples/nginx + ref: package-examples/nginx/v0.2 + repo: https://github.com/GoogleContainerTools/kpt + type: git +``` ### Apply the package -This step should describe the process and exact commands needed to deploy the resources to a live cluster. +It's possible to use kustomize build and kpt live apply. \ No newline at end of file diff --git a/package-examples/kustomize-pkg/overlays/dev/kustomization.yaml b/package-examples/kustomize-pkg/overlays/dev/kustomization.yaml index a2719c35d3..a2c07b2cd9 100644 --- a/package-examples/kustomize-pkg/overlays/dev/kustomization.yaml +++ b/package-examples/kustomize-pkg/overlays/dev/kustomization.yaml @@ -1,3 +1,17 @@ +# Copyright 2021 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. + apiVersion: kustomize.config.k8s.io/v1beta1 kind: Kustomization resources: diff --git a/package-examples/kustomize-pkg/overlays/dev/pass-patch.yaml b/package-examples/kustomize-pkg/overlays/dev/pass-patch.yaml index f9e9e0b668..3896d1e148 100644 --- a/package-examples/kustomize-pkg/overlays/dev/pass-patch.yaml +++ b/package-examples/kustomize-pkg/overlays/dev/pass-patch.yaml @@ -1,7 +1,21 @@ +# Copyright 2021 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. + apiVersion: apps/v1 kind: Deployment metadata: - name: not-important + name: deployment-patch spec: replicas: 1 template: diff --git a/package-examples/kustomize-pkg/overlays/prod/kustomization.yaml b/package-examples/kustomize-pkg/overlays/prod/kustomization.yaml index 7191afb0aa..f25f1f602c 100644 --- a/package-examples/kustomize-pkg/overlays/prod/kustomization.yaml +++ b/package-examples/kustomize-pkg/overlays/prod/kustomization.yaml @@ -1,3 +1,17 @@ +# Copyright 2021 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. + apiVersion: kustomize.config.k8s.io/v1beta1 kind: Kustomization resources: diff --git a/package-examples/kustomize-pkg/overlays/prod/pass-patch.yaml b/package-examples/kustomize-pkg/overlays/prod/pass-patch.yaml index c40e855eb6..f4764eeac5 100644 --- a/package-examples/kustomize-pkg/overlays/prod/pass-patch.yaml +++ b/package-examples/kustomize-pkg/overlays/prod/pass-patch.yaml @@ -1,7 +1,21 @@ +# Copyright 2021 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. + apiVersion: apps/v1 kind: Deployment metadata: - name: not-important + name: deployment-patch spec: replicas: 6 template: From 1e7aea9cd78e2889b2b87e1e771fe5be459f9b5f Mon Sep 17 00:00:00 2001 From: Mike Borozdin Date: Sat, 29 May 2021 09:07:31 -0700 Subject: [PATCH 4/9] updates to README --- package-examples/kustomize-pkg/README.md | 31 +++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/package-examples/kustomize-pkg/README.md b/package-examples/kustomize-pkg/README.md index 16bb3dc44b..ebed5a66d4 100644 --- a/package-examples/kustomize-pkg/README.md +++ b/package-examples/kustomize-pkg/README.md @@ -12,7 +12,7 @@ This is a simple package that shows how kpt packages can be used instead of remo ### Fetch the package -Get the example package on to local using `kpt pkg get`. Note that this package is for the example, wihin that package we are also fetch an nginx sub-package which is an alternative to having a remote base. +Get the example package on to local using `kpt pkg get`. Note that this package is for this example, wihin that package we are also using the nginx sub-package which is an alternative to having a remote base. ```shell $ kpt pkg get https://github.com/GoogleContainerTools/kpt.git/package-examples/kustomize-pkg @@ -67,7 +67,7 @@ namePrefix: dev- You can see the final configuration that the patch is going to render. The major difference between this and in place edit is that you can't just go to the file and look at it in isolation, you need to run `kustomize build` and examine the final results. ```shell -$ kustomize build +$ kustomize build kustomize-pkg/overlays/dev apiVersion: v1 kind: Service @@ -135,4 +135,29 @@ upstreamLock: ### Apply the package -It's possible to use kustomize build and kpt live apply. \ No newline at end of file +It's possible to use kustomize build and kpt live apply, but it does require passing the inventory to `kpt live apply` from `kustomize build` output. One of the base Kptfiles needs to be initialized with the inventory object. We will use the nginx base, but in real life exployment it might be better to initialize inventory on your root package. + +```shell +$ kpt live init bases/nginx + +initializing Kptfile inventory info (namespace: default)...success +``` + +We will also need to ensure that the Kptfile is a part of kustomize output and the simplest way to do it is just to add it to one of the kustomization.yaml files. In our case it's: kustomize-pkg/bases/nginx/kustomization.yaml + +```yaml +resources: +- deployment.yaml +- svc.yaml +- Kptfile +``` + +Note that because Kpt has a powerful package merge it's possible to add and change files locally and still get upstream changes. In this case the kustomization.yaml doesn't exist in the upstream package, we added it locally only. + +Kustomize build will need to be piped to kpt live apply: + +```shell +$ kustomize build kustomize-pkg/overlays/dev | kpt live apply - + +TODO - need to address the kpt live apply +``` \ No newline at end of file From 0f529583507f01e7ea721cc66ff22786a4e409f5 Mon Sep 17 00:00:00 2001 From: Mike Borozdin Date: Wed, 2 Jun 2021 22:36:35 -0700 Subject: [PATCH 5/9] update per PR feedback --- package-examples/kustomize-pkg/README.md | 59 ++++++------------- .../bases/nginx/kustomization.yaml | 1 - .../kustomize-pkg/overlays/dev/Kptfile | 6 ++ .../kustomize-pkg/overlays/dev/README.md | 21 +++++++ .../overlays/dev/kustomization.yaml | 1 + .../kustomize-pkg/overlays/prod/Kptfile | 6 ++ .../kustomize-pkg/overlays/prod/README.md | 21 +++++++ .../overlays/prod/kustomization.yaml | 1 + 8 files changed, 75 insertions(+), 41 deletions(-) create mode 100644 package-examples/kustomize-pkg/overlays/dev/Kptfile create mode 100644 package-examples/kustomize-pkg/overlays/dev/README.md create mode 100644 package-examples/kustomize-pkg/overlays/prod/Kptfile create mode 100644 package-examples/kustomize-pkg/overlays/prod/README.md diff --git a/package-examples/kustomize-pkg/README.md b/package-examples/kustomize-pkg/README.md index ebed5a66d4..c7ab2936f7 100644 --- a/package-examples/kustomize-pkg/README.md +++ b/package-examples/kustomize-pkg/README.md @@ -31,28 +31,31 @@ $ kpt pkg tree kustomize-pkg/ PKG: kustomize-pkg ├── [Kptfile] Kptfile kustomize-pkg ├── PKG: nginx -│ ├── [Kptfile] Kptfile nginx -│ ├── [deployment.yaml] Deployment my-nginx -│ └── [svc.yaml] Service my-nginx-svc -├── dev -│ ├── [kustomization.yaml] Kustomization -│ └── [pass-patch.yaml] Deployment deployment-patch -└── prod +│   ├── [Kptfile] Kptfile nginx +│   ├── [deployment.yaml] Deployment my-nginx +│   └── [svc.yaml] Service my-nginx-svc +├── PKG: dev +│   ├── [Kptfile] Kptfile dev +│   ├── [kustomization.yaml] Kustomization +│   └── [pass-patch.yaml] Deployment deployment-patch +└── PKG: prod + ├── [Kptfile] Kptfile prod ├── [kustomization.yaml] Kustomization └── [pass-patch.yaml] Deployment deployment-patch ``` ### kustomize the config -We recommend that you keep the kustomize instructions to rendering only such as adding a namespace, transforming or applying a patch. The second you mix kpt packages and remote bases you will be missing out on a big advantage of having a guaranteed stable base. +Kustomize is a great tool for out of place hydration, but we don't recommend that you mix kpt packages and remote bases. It's best to have a clear delienation what you are using each tools for: kpt for packages and remote resources, kustomize for hydration like adding labels, setting namespaces and overlays. -You can edit the patches and kustomize files we have created in the overlay folders. +In the example below what was a remote base is now fetched locally as a kpt package and kustomize is used for hydration. ```yaml apiVersion: kustomize.config.k8s.io/v1beta1 kind: Kustomization resources: - ../../bases/nginx +- Kptfile patches: - path: pass-patch.yaml target: @@ -109,50 +112,26 @@ spec: - containerPort: 80 --- apiVersion: kpt.dev/v1alpha2 +info: + description: sample description kind: Kptfile metadata: labels: environ: dev - name: dev-nginx -pipeline: - validators: - - image: gcr.io/kpt-fn/kubeval:v0.1 -upstream: - git: - directory: package-examples/nginx - ref: v0.2 - repo: https://github.com/GoogleContainerTools/kpt - type: git - updateStrategy: resource-merge -upstreamLock: - git: - commit: 4d2aa98b45ddee4b5fa45fbca16f2ff887de9efb - directory: package-examples/nginx - ref: package-examples/nginx/v0.2 - repo: https://github.com/GoogleContainerTools/kpt - type: git -``` + name: dev-dev + ### Apply the package -It's possible to use kustomize build and kpt live apply, but it does require passing the inventory to `kpt live apply` from `kustomize build` output. One of the base Kptfiles needs to be initialized with the inventory object. We will use the nginx base, but in real life exployment it might be better to initialize inventory on your root package. +It is possible to use kustomize build and kpt live apply, but it does require passing the inventory to `kpt live apply` from `kustomize build` output. It is best to have Kptfiles with inventory objects in overlay folders in case the variants of the package are deployed to the same cluster. Every variant of this application will need to be mapped to it\'s own inventory for pruning. In case you have two variants that use the same inventory object the consequent deploy might wipe out the previous variant. ```shell -$ kpt live init bases/nginx +$ kpt live init kustomize-pkg/overlays/dev initializing Kptfile inventory info (namespace: default)...success ``` -We will also need to ensure that the Kptfile is a part of kustomize output and the simplest way to do it is just to add it to one of the kustomization.yaml files. In our case it's: kustomize-pkg/bases/nginx/kustomization.yaml - -```yaml -resources: -- deployment.yaml -- svc.yaml -- Kptfile -``` - -Note that because Kpt has a powerful package merge it's possible to add and change files locally and still get upstream changes. In this case the kustomization.yaml doesn't exist in the upstream package, we added it locally only. +You might have noticed that the overlays have Kptfiles and they are added to the kustomization.yaml so the contents are passed all the way through the kustomize build. Kustomize build will need to be piped to kpt live apply: diff --git a/package-examples/kustomize-pkg/bases/nginx/kustomization.yaml b/package-examples/kustomize-pkg/bases/nginx/kustomization.yaml index 9be463c890..f0d9114cb1 100644 --- a/package-examples/kustomize-pkg/bases/nginx/kustomization.yaml +++ b/package-examples/kustomize-pkg/bases/nginx/kustomization.yaml @@ -1,4 +1,3 @@ resources: - deployment.yaml - svc.yaml -- Kptfile \ No newline at end of file diff --git a/package-examples/kustomize-pkg/overlays/dev/Kptfile b/package-examples/kustomize-pkg/overlays/dev/Kptfile new file mode 100644 index 0000000000..f41581e8a9 --- /dev/null +++ b/package-examples/kustomize-pkg/overlays/dev/Kptfile @@ -0,0 +1,6 @@ +apiVersion: kpt.dev/v1alpha2 +kind: Kptfile +metadata: + name: dev +info: + description: sample description diff --git a/package-examples/kustomize-pkg/overlays/dev/README.md b/package-examples/kustomize-pkg/overlays/dev/README.md new file mode 100644 index 0000000000..3b2773ba37 --- /dev/null +++ b/package-examples/kustomize-pkg/overlays/dev/README.md @@ -0,0 +1,21 @@ +# dev + +## Description +sample description + +## Usage + +### Fetch the package +`kpt pkg get REPO_URI[.git]/PKG_PATH[@VERSION] dev` +Details: https://kpt.dev/reference/pkg/get/ + +### View package content +`kpt pkg tree dev` +Details: https://kpt.dev/reference/pkg/tree/ + +### Apply the package +``` +kpt live init dev +kpt live apply dev --reconcile-timeout=2m --output=table +``` +Details: https://kpt.dev/reference/live/ diff --git a/package-examples/kustomize-pkg/overlays/dev/kustomization.yaml b/package-examples/kustomize-pkg/overlays/dev/kustomization.yaml index a2c07b2cd9..26f034ce32 100644 --- a/package-examples/kustomize-pkg/overlays/dev/kustomization.yaml +++ b/package-examples/kustomize-pkg/overlays/dev/kustomization.yaml @@ -16,6 +16,7 @@ apiVersion: kustomize.config.k8s.io/v1beta1 kind: Kustomization resources: - ../../bases/nginx +- Kptfile patches: - path: pass-patch.yaml target: diff --git a/package-examples/kustomize-pkg/overlays/prod/Kptfile b/package-examples/kustomize-pkg/overlays/prod/Kptfile new file mode 100644 index 0000000000..f93f8728a3 --- /dev/null +++ b/package-examples/kustomize-pkg/overlays/prod/Kptfile @@ -0,0 +1,6 @@ +apiVersion: kpt.dev/v1alpha2 +kind: Kptfile +metadata: + name: prod +info: + description: sample description diff --git a/package-examples/kustomize-pkg/overlays/prod/README.md b/package-examples/kustomize-pkg/overlays/prod/README.md new file mode 100644 index 0000000000..969bb66e05 --- /dev/null +++ b/package-examples/kustomize-pkg/overlays/prod/README.md @@ -0,0 +1,21 @@ +# prod + +## Description +sample description + +## Usage + +### Fetch the package +`kpt pkg get REPO_URI[.git]/PKG_PATH[@VERSION] prod` +Details: https://kpt.dev/reference/pkg/get/ + +### View package content +`kpt pkg tree prod` +Details: https://kpt.dev/reference/pkg/tree/ + +### Apply the package +``` +kpt live init prod +kpt live apply prod --reconcile-timeout=2m --output=table +``` +Details: https://kpt.dev/reference/live/ diff --git a/package-examples/kustomize-pkg/overlays/prod/kustomization.yaml b/package-examples/kustomize-pkg/overlays/prod/kustomization.yaml index f25f1f602c..1326e3af30 100644 --- a/package-examples/kustomize-pkg/overlays/prod/kustomization.yaml +++ b/package-examples/kustomize-pkg/overlays/prod/kustomization.yaml @@ -16,6 +16,7 @@ apiVersion: kustomize.config.k8s.io/v1beta1 kind: Kustomization resources: - ../../bases/nginx +- Kptfile patches: - path: pass-patch.yaml target: From 063a655992f5a10a940bfe677927b85a014862b0 Mon Sep 17 00:00:00 2001 From: Mike Borozdin Date: Wed, 2 Jun 2021 22:41:29 -0700 Subject: [PATCH 6/9] removed the README's in overlays --- .../kustomize-pkg/overlays/dev/README.md | 21 ------------------- .../kustomize-pkg/overlays/prod/README.md | 21 ------------------- 2 files changed, 42 deletions(-) delete mode 100644 package-examples/kustomize-pkg/overlays/dev/README.md delete mode 100644 package-examples/kustomize-pkg/overlays/prod/README.md diff --git a/package-examples/kustomize-pkg/overlays/dev/README.md b/package-examples/kustomize-pkg/overlays/dev/README.md deleted file mode 100644 index 3b2773ba37..0000000000 --- a/package-examples/kustomize-pkg/overlays/dev/README.md +++ /dev/null @@ -1,21 +0,0 @@ -# dev - -## Description -sample description - -## Usage - -### Fetch the package -`kpt pkg get REPO_URI[.git]/PKG_PATH[@VERSION] dev` -Details: https://kpt.dev/reference/pkg/get/ - -### View package content -`kpt pkg tree dev` -Details: https://kpt.dev/reference/pkg/tree/ - -### Apply the package -``` -kpt live init dev -kpt live apply dev --reconcile-timeout=2m --output=table -``` -Details: https://kpt.dev/reference/live/ diff --git a/package-examples/kustomize-pkg/overlays/prod/README.md b/package-examples/kustomize-pkg/overlays/prod/README.md deleted file mode 100644 index 969bb66e05..0000000000 --- a/package-examples/kustomize-pkg/overlays/prod/README.md +++ /dev/null @@ -1,21 +0,0 @@ -# prod - -## Description -sample description - -## Usage - -### Fetch the package -`kpt pkg get REPO_URI[.git]/PKG_PATH[@VERSION] prod` -Details: https://kpt.dev/reference/pkg/get/ - -### View package content -`kpt pkg tree prod` -Details: https://kpt.dev/reference/pkg/tree/ - -### Apply the package -``` -kpt live init prod -kpt live apply prod --reconcile-timeout=2m --output=table -``` -Details: https://kpt.dev/reference/live/ From 0761427870cbc027a617300c2fae4865dc850a1e Mon Sep 17 00:00:00 2001 From: Mike Borozdin Date: Wed, 2 Jun 2021 22:47:58 -0700 Subject: [PATCH 7/9] update to the readme --- package-examples/kustomize-pkg/README.md | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/package-examples/kustomize-pkg/README.md b/package-examples/kustomize-pkg/README.md index c7ab2936f7..ff54636763 100644 --- a/package-examples/kustomize-pkg/README.md +++ b/package-examples/kustomize-pkg/README.md @@ -9,6 +9,7 @@ This is a simple package that shows how kpt packages can be used instead of remo 3. [kustomize the config](#kustomize-the-config) 4. [Render the kustomization](#render-the-kustomization) 5. [Apply the package](#apply-the-package) +6. [Clean up resources](#clean-up-resources) ### Fetch the package @@ -123,7 +124,7 @@ metadata: ### Apply the package -It is possible to use kustomize build and kpt live apply, but it does require passing the inventory to `kpt live apply` from `kustomize build` output. It is best to have Kptfiles with inventory objects in overlay folders in case the variants of the package are deployed to the same cluster. Every variant of this application will need to be mapped to it\'s own inventory for pruning. In case you have two variants that use the same inventory object the consequent deploy might wipe out the previous variant. +It is possible to use kustomize build and kpt live apply, but it does require passing the inventory information to `kpt live apply` from `kustomize build` output. It is best to have Kptfiles with inventory information in overlay folders in case the variants of the package are deployed to the same cluster. Every variant of this application will need to be mapped to it\'s own inventory for pruning. In case you have two variants that use the same inventory information the consequent deploy might wipe out the previous variant. ```shell $ kpt live init kustomize-pkg/overlays/dev @@ -138,5 +139,20 @@ Kustomize build will need to be piped to kpt live apply: ```shell $ kustomize build kustomize-pkg/overlays/dev | kpt live apply - -TODO - need to address the kpt live apply +service/dev-my-nginx-svc created +deployment.apps/dev-my-nginx created +2 resource(s) applied. 2 created, 0 unchanged, 0 configured, 0 failed +0 resource(s) pruned, 0 skipped, 0 failed +``` + +### Clean up resources + +You can use kpt to prune and clean up resources from your build by using `kpt live destroy`. As long as the inventory information is passed in kpt will know how to clean everything up: + +```shell +$ kustomize build kustomize-pkg/overlays/dev | kpt live destroy - + +deployment.apps/dev-my-nginx deleted +service/dev-my-nginx-svc deleted +2 resource(s) deleted, 0 skipped ``` \ No newline at end of file From 031575349642790d2505cc6ee7df5be50aa2a902 Mon Sep 17 00:00:00 2001 From: Mike Borozdin Date: Thu, 3 Jun 2021 13:23:02 -0700 Subject: [PATCH 8/9] using tree command because of nested folders --- package-examples/kustomize-pkg/README.md | 36 +++++++++++++----------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/package-examples/kustomize-pkg/README.md b/package-examples/kustomize-pkg/README.md index ff54636763..0a19a0d33c 100644 --- a/package-examples/kustomize-pkg/README.md +++ b/package-examples/kustomize-pkg/README.md @@ -27,22 +27,26 @@ fetching package /package-examples/kustomize-pkg from https://github.com/GoogleC List the package contents in a tree structure. ```shell -$ kpt pkg tree kustomize-pkg/ - -PKG: kustomize-pkg -├── [Kptfile] Kptfile kustomize-pkg -├── PKG: nginx -│   ├── [Kptfile] Kptfile nginx -│   ├── [deployment.yaml] Deployment my-nginx -│   └── [svc.yaml] Service my-nginx-svc -├── PKG: dev -│   ├── [Kptfile] Kptfile dev -│   ├── [kustomization.yaml] Kustomization -│   └── [pass-patch.yaml] Deployment deployment-patch -└── PKG: prod - ├── [Kptfile] Kptfile prod - ├── [kustomization.yaml] Kustomization - └── [pass-patch.yaml] Deployment deployment-patch +$ tree kustomize-pkg + +kustomize-pkg +├── Kptfile +├── README.md +├── bases +│   └── nginx +│   ├── Kptfile +│   ├── deployment.yaml +│   ├── kustomization.yaml +│   └── svc.yaml +└── overlays + ├── dev + │   ├── Kptfile + │   ├── kustomization.yaml + │   └── pass-patch.yaml + └── prod + ├── Kptfile + ├── kustomization.yaml + └── pass-patch.yaml ``` ### kustomize the config From eddfd6c2b0768c555a2d97a4bbb293d83802cb39 Mon Sep 17 00:00:00 2001 From: Mike Borozdin Date: Thu, 3 Jun 2021 15:30:46 -0700 Subject: [PATCH 9/9] updated the pkg get to point to next --- package-examples/helloworld-set/README.md | 2 +- package-examples/helloworld-tshirt/README.md | 2 +- package-examples/helloworld/README.md | 2 +- package-examples/kustomize-pkg/README.md | 2 +- package-examples/pipeline-validate/README.md | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package-examples/helloworld-set/README.md b/package-examples/helloworld-set/README.md index f2bcbf3d66..0da78e29cf 100644 --- a/package-examples/helloworld-set/README.md +++ b/package-examples/helloworld-set/README.md @@ -16,7 +16,7 @@ setters in it. Get the example package on to local using `kpt pkg get` ```shell -$ kpt pkg get https://github.com/GoogleContainerTools/kpt.git/package-examples/helloworld-set +$ kpt pkg get https://github.com/GoogleContainerTools/kpt.git/package-examples/helloworld-set@next fetching package /package-examples/helloworld-set from https://github.com/GoogleContainerTools/kpt to helloworld-set ``` diff --git a/package-examples/helloworld-tshirt/README.md b/package-examples/helloworld-tshirt/README.md index 5012ad6f0e..d30682e755 100644 --- a/package-examples/helloworld-tshirt/README.md +++ b/package-examples/helloworld-tshirt/README.md @@ -18,7 +18,7 @@ resource sizes. Get the example package on to local using `kpt pkg get` ```shell -$ kpt pkg get https://github.com/GoogleContainerTools/kpt.git/package-examples/helloworld-tshirt +$ kpt pkg get https://github.com/GoogleContainerTools/kpt.git/package-examples/helloworld-tshirt@next fetching package /package-examples/helloworld-tshirt from https://github.com/GoogleContainerTools/kpt to helloworld-tshirt ``` diff --git a/package-examples/helloworld/README.md b/package-examples/helloworld/README.md index f94bfd1ff7..f61dbeb554 100644 --- a/package-examples/helloworld/README.md +++ b/package-examples/helloworld/README.md @@ -14,7 +14,7 @@ doesn't do anything beyond declaring the current directory as a `kpt` package. Get the example package on to local using `kpt pkg get` ```shell -$ kpt pkg get https://github.com/GoogleContainerTools/kpt.git/package-examples/helloworld +$ kpt pkg get https://github.com/GoogleContainerTools/kpt.git/package-examples/helloworld@next fetching package /package-examples/helloworld from https://github.com/GoogleContainerTools/kpt to helloworld ``` diff --git a/package-examples/kustomize-pkg/README.md b/package-examples/kustomize-pkg/README.md index 0a19a0d33c..834591e0cb 100644 --- a/package-examples/kustomize-pkg/README.md +++ b/package-examples/kustomize-pkg/README.md @@ -16,7 +16,7 @@ This is a simple package that shows how kpt packages can be used instead of remo Get the example package on to local using `kpt pkg get`. Note that this package is for this example, wihin that package we are also using the nginx sub-package which is an alternative to having a remote base. ```shell -$ kpt pkg get https://github.com/GoogleContainerTools/kpt.git/package-examples/kustomize-pkg +$ kpt pkg get https://github.com/GoogleContainerTools/kpt.git/package-examples/kustomize-pkg@next fetching package /package-examples/kustomize-pkg from https://github.com/GoogleContainerTools/kpt to kustomize-pkg ``` diff --git a/package-examples/pipeline-validate/README.md b/package-examples/pipeline-validate/README.md index bf7ae4afd4..de2169d0d8 100644 --- a/package-examples/pipeline-validate/README.md +++ b/package-examples/pipeline-validate/README.md @@ -26,7 +26,7 @@ validate and apply the package: Get the example package on to local using `kpt pkg get` ```shell -$ kpt pkg get https://github.com/GoogleContainerTools/kpt.git/package-examples/pipeline-validate +$ kpt pkg get https://github.com/GoogleContainerTools/kpt.git/package-examples/pipeline-validate@next fetching package /package-examples/pipeline-validate from https://github.com/GoogleContainerTools/kpt to pipeline-validate ```