-
Couldn't load subscription status.
- Fork 71
Fix possible nil-pointer error; add golden test for set-name-prefix #926
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -76,34 +76,37 @@ func VisitRefs(objects fn.KubeObjects, visitor func(ref Ref) error) error { | |
| } | ||
|
|
||
| func visitFields(object *fn.KubeObject, subObject *fn.SubObject, fields []string, refInfo *refInfo, visitor func(ref Ref) error) error { | ||
| // Guard against nil objects | ||
| if subObject == nil { | ||
| return nil | ||
| } | ||
|
|
||
| if len(fields) == 0 { | ||
| if subObject != nil { | ||
| // Ignore external refs, these don't get renamed | ||
| // TODO: Check if supports external ?? | ||
| external := subObject.GetString("external") | ||
| if external != "" { | ||
| return nil | ||
| } | ||
| // Ignore external refs, these don't get renamed | ||
| // TODO: Check if supports external ?? | ||
| external := subObject.GetString("external") | ||
| if external != "" { | ||
| return nil | ||
| } | ||
|
|
||
| ref, err := refInfo.buildFullyQualifiedRef(object, subObject) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| if err := visitor(ref); err != nil { | ||
| return err | ||
| } | ||
| ref, err := refInfo.buildFullyQualifiedRef(object, subObject) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| if err := visitor(ref); err != nil { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. super nit: seems to be more readable as "visit"? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ignore this comment. Didn't notice this is a common naming convention in go. |
||
| return err | ||
| } | ||
|
|
||
| if refInfo.NamespaceFieldPath != "" { | ||
| namespaceFieldPath := strings.Split(refInfo.NamespaceFieldPath, ".") | ||
| namespace, _, _ := subObject.NestedString(namespaceFieldPath...) | ||
| if namespace != "" { | ||
| ref, err := buildRefNamespaceReference(subObject, namespaceFieldPath...) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| if err := visitor(ref); err != nil { | ||
| return err | ||
| } | ||
| if refInfo.NamespaceFieldPath != "" { | ||
| namespaceFieldPath := strings.Split(refInfo.NamespaceFieldPath, ".") | ||
| namespace, _, _ := subObject.NestedString(namespaceFieldPath...) | ||
| if namespace != "" { | ||
| ref, err := buildRefNamespaceReference(subObject, namespaceFieldPath...) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| if err := visitor(ref); err != nil { | ||
| return err | ||
| } | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| // 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. | ||
|
|
||
| package main | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/GoogleContainerTools/kpt-functions-sdk/go/fn" | ||
| "github.com/GoogleContainerTools/kpt-functions-sdk/go/fn/testhelpers" | ||
| ) | ||
|
|
||
| func TestFunctions(t *testing.T) { | ||
| testhelpers.RunGoldenTests(t, "testdata", fn.ResourceListProcessorFunc(Run)) | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| apiVersion: config.kubernetes.io/v1 | ||
| kind: ResourceList | ||
| items: | ||
| - apiVersion: iam.cnrm.cloud.google.com/v1beta1 | ||
| kind: IAMPartialPolicy | ||
| metadata: | ||
| name: simple1-editors | ||
| namespace: config-control | ||
| spec: | ||
| bindings: | ||
| - members: | ||
| - member: user:[email protected] | ||
| role: roles/editor | ||
| resourceRef: | ||
| apiVersion: resourcemanager.cnrm.cloud.google.com/v1beta1 | ||
| kind: Project | ||
| name: simple1 | ||
| - apiVersion: resourcemanager.cnrm.cloud.google.com/v1beta1 | ||
| kind: Folder | ||
| metadata: | ||
| name: simple1 | ||
| namespace: config-control | ||
| spec: | ||
| displayName: packagename | ||
| folderRef: | ||
| name: environments | ||
| - apiVersion: resourcemanager.cnrm.cloud.google.com/v1beta1 | ||
| kind: Project | ||
| metadata: | ||
| name: simple1 | ||
| namespace: config-control | ||
| spec: | ||
| name: packagename | ||
| folderRef: | ||
| name: environments | ||
| - # We need to enable some services so we can enable other services | ||
| apiVersion: serviceusage.cnrm.cloud.google.com/v1beta1 | ||
| kind: Service | ||
| metadata: | ||
| annotations: | ||
| cnrm.cloud.google.com/deletion-policy: "abandon" | ||
| name: simple1-serviceusage | ||
| namespace: config-control | ||
| spec: | ||
| resourceID: serviceusage.googleapis.com | ||
| projectRef: | ||
| name: simple1 | ||
| - # Needed to grant GCP IAM permissions on projects | ||
| apiVersion: serviceusage.cnrm.cloud.google.com/v1beta1 | ||
| kind: Service | ||
| metadata: | ||
| annotations: | ||
| cnrm.cloud.google.com/deletion-policy: "abandon" | ||
| name: cloudresourcemanager.googleapis.com | ||
| namespace: packagename | ||
| - apiVersion: serviceusage.cnrm.cloud.google.com/v1beta1 | ||
| kind: Service | ||
| metadata: | ||
| annotations: | ||
| cnrm.cloud.google.com/deletion-policy: "abandon" | ||
| name: container.googleapis.com | ||
| namespace: packagename | ||
| - apiVersion: v1 | ||
| kind: ConfigMap | ||
| metadata: | ||
| name: kptfile.kpt.dev | ||
| annotations: | ||
| config.kubernetes.io/local-config: "true" | ||
| data: | ||
| name: simple1 | ||
| functionConfig: | ||
| kind: ConfigMap | ||
| apiVersion: v1 | ||
| data: {} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| kind: ConfigMap | ||
| apiVersion: v1 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| apiVersion: v1 | ||
| kind: ConfigMap | ||
| metadata: | ||
| name: kptfile.kpt.dev | ||
| annotations: | ||
| config.kubernetes.io/local-config: "true" | ||
| data: | ||
| name: simple1 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| apiVersion: resourcemanager.cnrm.cloud.google.com/v1beta1 | ||
| kind: Folder | ||
| metadata: | ||
| name: packagename | ||
| namespace: config-control | ||
| spec: | ||
| displayName: packagename | ||
| folderRef: | ||
| name: environments | ||
|
|
||
| --- | ||
|
|
||
| apiVersion: resourcemanager.cnrm.cloud.google.com/v1beta1 | ||
| kind: Project | ||
| metadata: | ||
| name: packagename | ||
| namespace: config-control | ||
| spec: | ||
| name: packagename | ||
| folderRef: | ||
| name: environments | ||
|
|
||
| --- | ||
|
|
||
| # We need to enable some services so we can enable other services | ||
| apiVersion: serviceusage.cnrm.cloud.google.com/v1beta1 | ||
| kind: Service | ||
| metadata: | ||
| annotations: | ||
| cnrm.cloud.google.com/deletion-policy: "abandon" | ||
| name: packagename-serviceusage | ||
| namespace: config-control | ||
| spec: | ||
| resourceID: serviceusage.googleapis.com | ||
| projectRef: | ||
| name: packagename | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| apiVersion: iam.cnrm.cloud.google.com/v1beta1 | ||
| kind: IAMPartialPolicy | ||
| metadata: | ||
| name: packagename-editors | ||
| namespace: config-control | ||
| spec: | ||
| bindings: | ||
| - members: | ||
| - member: user:[email protected] | ||
| role: roles/editor | ||
| resourceRef: | ||
| apiVersion: resourcemanager.cnrm.cloud.google.com/v1beta1 | ||
| kind: Project | ||
| name: packagename |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| apiVersion: serviceusage.cnrm.cloud.google.com/v1beta1 | ||
| kind: Service | ||
| metadata: | ||
| annotations: | ||
| cnrm.cloud.google.com/deletion-policy: "abandon" | ||
| name: container.googleapis.com | ||
| namespace: packagename | ||
|
|
||
| --- | ||
|
|
||
| # Needed to grant GCP IAM permissions on projects | ||
| apiVersion: serviceusage.cnrm.cloud.google.com/v1beta1 | ||
| kind: Service | ||
| metadata: | ||
| annotations: | ||
| cnrm.cloud.google.com/deletion-policy: "abandon" | ||
| name: cloudresourcemanager.googleapis.com | ||
| namespace: packagename |
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.
I like the name "FullyQualified"!