-
Notifications
You must be signed in to change notification settings - Fork 67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add tests to ensure functions preserve comments #324
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,40 @@ | ||
diff --git a/resources.yaml b/resources.yaml | ||
index 968a0f4..a33d07a 100644 | ||
index 2ce8de6..6c12c43 100644 | ||
--- a/resources.yaml | ||
+++ b/resources.yaml | ||
@@ -1,22 +1,22 @@ | ||
@@ -2,24 +2,24 @@ | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
- labels: | ||
- foo: bar | ||
- env: dev | ||
- env: dev # must be one of prod, staging and dev | ||
name: my-nginx | ||
# namespace for team foo | ||
namespace: my-space | ||
+ labels: | ||
+ env: dev | ||
+ env: dev # must be one of prod, staging and dev | ||
+ foo: bar | ||
spec: | ||
+ # The desired replicas | ||
+ replicas: 3 | ||
selector: | ||
- matchLabels: | ||
- app: nginx | ||
spec: | ||
containers: | ||
- - image: nginx:1.14.2 | ||
- - image: nginx:1.14.2 # version should be >= 1.14.2 | ||
- name: nginx | ||
- ports: | ||
- - containerPort: 80 | ||
- # The desired replicas | ||
- replicas: 3 | ||
+ - name: nginx | ||
+ image: nginx:1.14.2 | ||
+ image: nginx:1.14.2 # version should be >= 1.14.2 | ||
+ ports: | ||
+ - containerPort: 80 | ||
+ matchLabels: | ||
+ app: nginx | ||
template: | ||
template: # pod template | ||
metadata: | ||
labels: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,26 @@ | ||
# This is a Deployment for app foo | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
labels: | ||
foo: bar | ||
env: dev | ||
env: dev # must be one of prod, staging and dev | ||
name: my-nginx | ||
# namespace for team foo | ||
namespace: my-space | ||
spec: | ||
selector: | ||
matchLabels: | ||
app: nginx | ||
spec: | ||
containers: | ||
- image: nginx:1.14.2 | ||
- image: nginx:1.14.2 # version should be >= 1.14.2 | ||
name: nginx | ||
ports: | ||
- containerPort: 80 | ||
# The desired replicas | ||
replicas: 3 | ||
template: | ||
template: # pod template | ||
metadata: | ||
labels: | ||
app: nginx |
29 changes: 29 additions & 0 deletions
29
tests/ensure-name-substring/preserve-comments/.expected/diff.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
diff --git a/resources.yaml b/resources.yaml | ||
index a1830c3..ce16eb1 100644 | ||
--- a/resources.yaml | ||
+++ b/resources.yaml | ||
@@ -3,7 +3,7 @@ | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: # comment 3 | ||
- name: the-map # comment 4 | ||
+ name: prod-the-map # comment 4 | ||
namespace: the-namespace | ||
data: | ||
some-key: some-value | ||
@@ -12,7 +12,7 @@ data: | ||
apiVersion: v1 | ||
kind: Pod | ||
metadata: | ||
- name: the-pod | ||
+ name: prod-the-pod | ||
namespace: the-namespace | ||
spec: | ||
containers: # comment 6 | ||
@@ -26,5 +26,5 @@ spec: | ||
- name: SOME_KEY | ||
valueFrom: | ||
configMapKeyRef: # comment 7 | ||
- name: the-map # comment 8 | ||
+ name: prod-the-map # comment 8 | ||
key: some-key |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
apiVersion: kpt.dev/v1alpha2 | ||
kind: Kptfile | ||
metadata: | ||
name: example | ||
pipeline: | ||
mutators: | ||
- image: gcr.io/kpt-fn/ensure-name-substring:unstable | ||
configMap: | ||
prepend: prod- |
30 changes: 30 additions & 0 deletions
30
tests/ensure-name-substring/preserve-comments/resources.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# comment 1 | ||
# comment 2 | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: # comment 3 | ||
name: the-map # comment 4 | ||
namespace: the-namespace | ||
data: | ||
some-key: some-value | ||
--- | ||
# comment 5 | ||
apiVersion: v1 | ||
kind: Pod | ||
metadata: | ||
name: the-pod | ||
namespace: the-namespace | ||
spec: | ||
containers: # comment 6 | ||
- name: test-container | ||
image: k8s.gcr.io/busybox | ||
command: | ||
- /bin/sh | ||
- -c | ||
- env | ||
env: | ||
- name: SOME_KEY | ||
valueFrom: | ||
configMapKeyRef: # comment 7 | ||
name: the-map # comment 8 | ||
key: some-key |
21 changes: 21 additions & 0 deletions
21
tests/set-annotations/preserve-comments/.expected/diff.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
diff --git a/resources.yaml b/resources.yaml | ||
index bc3856e..41a8456 100644 | ||
--- a/resources.yaml | ||
+++ b/resources.yaml | ||
@@ -5,7 +5,8 @@ kind: ConfigMap | ||
metadata: # comment 3 | ||
name: the-map | ||
annotations: | ||
- color: red # comment 4 | ||
+ color: orange # comment 4 | ||
+ fruit: apple | ||
# comment 5 | ||
data: | ||
some-key: some-value | ||
@@ -15,3 +16,6 @@ apiVersion: v1 | ||
kind: Namespace | ||
metadata: | ||
name: ns | ||
+ annotations: | ||
+ color: orange | ||
+ fruit: apple |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.expected |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
apiVersion: kpt.dev/v1alpha2 | ||
kind: Kptfile | ||
metadata: | ||
name: example | ||
pipeline: | ||
mutators: | ||
- image: gcr.io/kpt-fn/set-annotations:unstable | ||
configMap: | ||
color: orange | ||
fruit: apple |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# comment 1 | ||
# comment 2 | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: # comment 3 | ||
name: the-map | ||
annotations: | ||
color: red # comment 4 | ||
# comment 5 | ||
data: | ||
some-key: some-value | ||
--- | ||
# comment 6 | ||
apiVersion: v1 | ||
kind: Namespace | ||
metadata: | ||
name: ns |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
diff --git a/resources.yaml b/resources.yaml | ||
index 0bf78e1..e14316d 100644 | ||
--- a/resources.yaml | ||
+++ b/resources.yaml | ||
@@ -5,7 +5,8 @@ kind: ConfigMap | ||
metadata: # comment 4 | ||
name: the-map | ||
labels: # comment 5 | ||
- color: red # comment 6 | ||
+ color: orange # comment 6 | ||
+ fruit: apple | ||
data: | ||
some-key: some-value | ||
--- | ||
@@ -15,6 +16,9 @@ kind: MyResource | ||
metadata: | ||
name: the-service | ||
namespace: the-namespace | ||
+ labels: | ||
+ color: orange | ||
+ fruit: apple | ||
spec: # comment 8 | ||
selector: | ||
labels: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.expected |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
apiVersion: kpt.dev/v1alpha2 | ||
kind: Kptfile | ||
metadata: | ||
name: example | ||
pipeline: | ||
mutators: | ||
- image: gcr.io/kpt-fn/set-labels:unstable | ||
configMap: | ||
color: orange | ||
fruit: apple |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# comment 1 | ||
# comment 2 | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: # comment 4 | ||
name: the-map | ||
labels: # comment 5 | ||
color: red # comment 6 | ||
data: | ||
some-key: some-value | ||
--- | ||
# comment 7 | ||
apiVersion: dev.example.com/v1 | ||
kind: MyResource | ||
metadata: | ||
name: the-service | ||
namespace: the-namespace | ||
spec: # comment 8 | ||
selector: | ||
labels: | ||
foo: bar |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
21 changes: 21 additions & 0 deletions
21
tests/set-namespace/preserve-comments/.expected/diff.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
diff --git a/resources.yaml b/resources.yaml | ||
index d964587..24d1386 100644 | ||
--- a/resources.yaml | ||
+++ b/resources.yaml | ||
@@ -4,6 +4,7 @@ apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: # comment 3 | ||
name: the-map | ||
+ namespace: example-ns | ||
data: | ||
some-key: some-value # comment 4 | ||
--- | ||
@@ -12,7 +13,7 @@ apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: the-service | ||
- namespace: the-namespace | ||
+ namespace: example-ns | ||
spec: # comment 6 | ||
ports: | ||
- name: etcd-server-ssl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.expected |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# comment 1 | ||
# comment 2 | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: # comment 3 | ||
name: the-map | ||
data: | ||
some-key: some-value # comment 4 | ||
--- | ||
# comment 5 | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: the-service | ||
namespace: the-namespace | ||
spec: # comment 6 | ||
ports: | ||
- name: etcd-server-ssl | ||
port: 2380 | ||
- name: etcd-client-ssl | ||
port: 2379 | ||
clusterIP: None | ||
publishNotReadyAddresses: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
diff --git a/resources.yaml b/resources.yaml | ||
index 4a2f098..5d6b87a 100644 | ||
--- a/resources.yaml | ||
+++ b/resources.yaml | ||
@@ -4,7 +4,7 @@ apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: my-cm | ||
- namespace: my-ns # comment 3 | ||
+ namespace: prod # comment 3 | ||
data: | ||
# comment 4 | ||
some-key: some-value | ||
@@ -14,5 +14,6 @@ apiVersion: foo.com/v1 | ||
kind: Bar | ||
metadata: | ||
name: my-bar | ||
+ namespace: prod | ||
spec: | ||
featureA: true # comment 6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.expected |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
apiVersion: kpt.dev/v1alpha2 | ||
kind: Kptfile | ||
metadata: | ||
name: example | ||
pipeline: | ||
mutators: | ||
- image: gcr.io/kpt-fn/starlark:unstable | ||
configPath: fn-config.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
apiVersion: fn.kpt.dev/v1alpha1 | ||
kind: StarlarkRun | ||
metadata: | ||
name: set-namespace-to-prod | ||
source: | | ||
# set the namespace on all resources | ||
def setnamespace(resources, namespace): | ||
for resource in resources: | ||
# mutate the resource | ||
resource["metadata"]["namespace"] = namespace | ||
setnamespace(ctx.resource_list["items"], "prod") |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you explain the formatting changes in the PR description.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This diff is from the
format
function. The formatting change is desired.And also this line is not changed in this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@phanimarupaka I think we disabled the formatting now? Not sure.