Skip to content

Commit

Permalink
feat: set-namespace without kyaml/rnode dependencies (#769)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuwenma committed May 4, 2022
1 parent 31f2283 commit 54d6681
Show file tree
Hide file tree
Showing 55 changed files with 886 additions and 1,864 deletions.
38 changes: 0 additions & 38 deletions examples/set-namespace-advanced/.expected/diff.patch

This file was deleted.

1 change: 0 additions & 1 deletion examples/set-namespace-advanced/.krmignore

This file was deleted.

8 changes: 0 additions & 8 deletions examples/set-namespace-advanced/Kptfile

This file was deleted.

70 changes: 0 additions & 70 deletions examples/set-namespace-advanced/README.md

This file was deleted.

11 changes: 0 additions & 11 deletions examples/set-namespace-advanced/fn-config.yaml

This file was deleted.

34 changes: 0 additions & 34 deletions examples/set-namespace-advanced/resources.yaml

This file was deleted.

16 changes: 4 additions & 12 deletions examples/set-namespace-imperative/.expected/diff.patch
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
diff --git a/app.yaml b/app.yaml
index 53c70b1..15a02f9 100644
index 1f8aeee..33e42da 100644
--- a/app.yaml
+++ b/app.yaml
@@ -2,6 +2,7 @@ apiVersion: v1
kind: ConfigMap
metadata:
name: the-map
+ namespace: example-ns
data:
some-key: some-value
---
@@ -9,7 +10,7 @@ apiVersion: v1
@@ -9,7 +9,7 @@ apiVersion: v1
kind: Service
metadata:
name: the-service
Expand All @@ -19,9 +11,9 @@ index 53c70b1..15a02f9 100644
spec:
ports:
- name: etcd-server-ssl
@@ -21,4 +22,4 @@ spec:
@@ -21,4 +21,4 @@ spec:
apiVersion: v1
kind: Namespace
metadata:
- name: old-name
- name: example
+ name: example-ns
2 changes: 1 addition & 1 deletion examples/set-namespace-imperative/app.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ spec:
apiVersion: v1
kind: Namespace
metadata:
name: old-name
name: example
48 changes: 32 additions & 16 deletions examples/set-namespace-simple/.expected/diff.patch
Original file line number Diff line number Diff line change
@@ -1,27 +1,43 @@
diff --git a/resources.yaml b/resources.yaml
index 468897a..8d5a446 100644
index 85885ac..f93e6a4 100644
--- a/resources.yaml
+++ b/resources.yaml
@@ -2,6 +2,7 @@ apiVersion: v1
kind: ConfigMap
metadata:
name: the-map
+ namespace: example-ns
data:
some-key: some-value
---
@@ -9,7 +10,7 @@ apiVersion: v1
@@ -2,12 +2,12 @@ apiVersion: v1
kind: Service
metadata:
name: the-service
- namespace: the-namespace
- namespace: example
+ namespace: example-ns
spec:
ports:
- name: etcd-server-ssl
@@ -22,4 +23,4 @@ spec:
---
apiVersion: v1
kind: Namespace
metadata:
- name: old-name
- name: example
+ name: example-ns
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
@@ -20,7 +20,7 @@ spec:
clientConfig:
service:
name: crd-svc
- namespace: example
+ namespace: example-ns
---
apiVersion: apiregistration.k8s.io/v1
kind: APIService
@@ -29,7 +29,7 @@ metadata:
spec:
service:
name: api-svc
- namespace: example
+ namespace: example-ns
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
@@ -38,4 +38,4 @@ metadata:
subjects:
- kind: ServiceAccount
name: default
- namespace: example
+ namespace: example-ns
7 changes: 3 additions & 4 deletions examples/set-namespace-simple/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

### Overview

This example demonstrates how to declaratively run [`set-namespace`] function
to adds or replaces the `.metadata.namespace` field on all resources except for
those known to be cluster-scoped.
This example demonstrates how to run [`set-namespace`] function
to replace the `namespace` resource type in a variety of KRM resources.

### Fetch the example package

Expand Down Expand Up @@ -42,6 +41,6 @@ $ kpt fn render set-namespace-simple

### Expected result

Check all resources have `metadata.namespace` set to `example-ns`:
Check all resources have `metadata.namespace` set to `example-ns`

[`set-namespace`]: https://catalog.kpt.dev/set-namespace/v0.1/
50 changes: 33 additions & 17 deletions examples/set-namespace-simple/resources.yaml
Original file line number Diff line number Diff line change
@@ -1,25 +1,41 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: the-map
data:
some-key: some-value
---
apiVersion: v1
kind: Service
metadata:
name: the-service
namespace: the-namespace
spec:
ports:
- name: etcd-server-ssl
port: 2380
- name: etcd-client-ssl
port: 2379
clusterIP: None
publishNotReadyAddresses: true
namespace: example
---
apiVersion: v1
kind: Namespace
metadata:
name: old-name
name: example
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: the-crd
spec:
conversion:
strategy: Webhook
webhook:
clientConfig:
service:
name: crd-svc
namespace: example
---
apiVersion: apiregistration.k8s.io/v1
kind: APIService
metadata:
name: the-api-service
spec:
service:
name: api-svc
namespace: example
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: crb1
subjects:
- kind: ServiceAccount
name: default
namespace: example
Loading

0 comments on commit 54d6681

Please sign in to comment.