Skip to content

[WIP] proof test zyy98/image #906

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

Open
wants to merge 37 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
4b46ef1
draft PR for set-image refactor
zyy98 Aug 12, 2022
5095295
fix dead code
zyy98 Aug 12, 2022
e2ba056
update with new fn.ResourceRef
zyy98 Aug 12, 2022
4f807a4
dead code clean up
zyy98 Aug 12, 2022
e2eaeb1
change wording
zyy98 Aug 12, 2022
7b6f2b6
change sequence
zyy98 Aug 12, 2022
788e264
retrigger CI
zyy98 Aug 12, 2022
9337d74
refactor set-image with Runner interface, change unit tests into e2e …
zyy98 Aug 22, 2022
3523d1a
Merge remote-tracking branch 'origin/image' into image
zyy98 Aug 22, 2022
290f62a
merge delete old file
zyy98 Aug 22, 2022
e3d378c
dead code deletion
zyy98 Aug 22, 2022
bd67479
modify results and kptfile for set-image tests
zyy98 Aug 23, 2022
f4c9554
updates after review. Add image_util, change docstring and naming
zyy98 Aug 24, 2022
ede9aa8
missing util function
zyy98 Aug 24, 2022
43e788b
delete dead name and fix golang S1008
zyy98 Aug 24, 2022
d7fceff
update e2e results
zyy98 Aug 24, 2022
5588242
minor bug
zyy98 Aug 24, 2022
0ea287b
change wording according to Natasha's suggestions
zyy98 Aug 24, 2022
985f15b
change setImage to t
zyy98 Aug 24, 2022
df0faa5
change wording
zyy98 Aug 24, 2022
321a204
revert util
zyy98 Aug 24, 2022
6d697eb
wording for ConfigMap
zyy98 Aug 24, 2022
dfa575d
change e2e results accordingly
zyy98 Aug 24, 2022
aa57b76
change context from field within SetImage to parameters passed in to …
zyy98 Aug 24, 2022
8e2209b
avoid duplication for set containers
zyy98 Aug 24, 2022
6fb9e1d
avoid duplicate variables in updateImage function; check if name rema…
zyy98 Aug 24, 2022
c8a385f
change from image_util to fork
zyy98 Aug 24, 2022
c668017
change hasPod method. Change set Pod method
zyy98 Aug 24, 2022
82dec2d
refactor name
zyy98 Aug 24, 2022
fae129f
FsSlice using fn package as well
zyy98 Aug 25, 2022
119fe13
refactor result struct
zyy98 Aug 25, 2022
b1a4f72
minor docstring change
zyy98 Aug 25, 2022
ebdf78a
add adaptor
zyy98 Aug 25, 2022
d7d21c7
doc string and sequence change
zyy98 Aug 25, 2022
4b2d8cd
retrigger CI
zyy98 Aug 25, 2022
5e7c161
add back api
yuwenma Aug 25, 2022
6e75d89
bypass wasm dependency
yuwenma Aug 25, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ jobs:
go-version: 1.17
- name: Install kpt
run: |
go install github.com/GoogleContainerTools/kpt@main
go install github.com/GoogleContainerTools/kpt@v1.0.0-beta.17
- name: Build node and Go docker images
if: matrix.platform == 'ubuntu-latest'
run: |
Expand Down
14 changes: 4 additions & 10 deletions examples/set-image-advanced/.expected/results.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,23 @@ items:
- image: gcr.io/kpt-fn/set-image:unstable
exitCode: 0
results:
- message: set image from nginx:1.20.2 to bitnami/nginx:1.21.4
- message: updated image from nginx:1.20.2 to bitnami/nginx:1.21.4
severity: info
resourceRef:
apiVersion: v1
kind: Pod
name: the-pod
field:
path: spec.containers.image
currentValue: nginx:1.20.2
proposedValue: bitnami/nginx:1.21.4
file:
path: resources.yaml
- message: set image from nginx:1.20.2 to bitnami/nginx:1.21.4
- message: updated image from nginx:1.20.2 to bitnami/nginx:1.21.4
severity: info
resourceRef:
apiVersion: dev.example.com/v1
kind: MyKind
name: the-resource
namespace: the-namespace
field:
path: spec.manifest.images.image
currentValue: nginx:1.20.2
proposedValue: bitnami/nginx:1.21.4
file:
path: resources.yaml
index: 1
- message: 'summary: updated a total of 1 image(s)'
severity: info
14 changes: 4 additions & 10 deletions examples/set-image-digest/.expected/results.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,22 @@ items:
- image: gcr.io/kpt-fn/set-image:unstable
exitCode: 0
results:
- message: set image from nginx:1.20.2 to bitnami/nginx@sha256:e1d6f00f191515945233f562777fc9ab3b7637ea75169b3dd628d46c9b24400f
- message: updated image from nginx:1.20.2 to bitnami/nginx@sha256:e1d6f00f191515945233f562777fc9ab3b7637ea75169b3dd628d46c9b24400f
severity: info
resourceRef:
apiVersion: v1
kind: Pod
name: app1
field:
path: spec.containers.image
currentValue: nginx:1.20.2
proposedValue: bitnami/nginx@sha256:e1d6f00f191515945233f562777fc9ab3b7637ea75169b3dd628d46c9b24400f
file:
path: resources.yaml
- message: set image from nginx:1.20.2 to bitnami/nginx@sha256:e1d6f00f191515945233f562777fc9ab3b7637ea75169b3dd628d46c9b24400f
- message: updated image from nginx:1.20.2 to bitnami/nginx@sha256:e1d6f00f191515945233f562777fc9ab3b7637ea75169b3dd628d46c9b24400f
severity: info
resourceRef:
apiVersion: v1
kind: Pod
name: app2
field:
path: spec.containers.image
currentValue: nginx:1.20.2
proposedValue: bitnami/nginx@sha256:e1d6f00f191515945233f562777fc9ab3b7637ea75169b3dd628d46c9b24400f
file:
path: resources.yaml
index: 1
- message: 'summary: updated a total of 2 image(s)'
severity: info
14 changes: 4 additions & 10 deletions examples/set-image-imperative/.expected/results.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,22 @@ items:
- image: gcr.io/kpt-fn/set-image:unstable
exitCode: 0
results:
- message: set image from nginx:1.20.2 to bitnami/nginx:1.21.4
- message: updated image from nginx:1.20.2 to bitnami/nginx:1.21.4
severity: info
resourceRef:
apiVersion: v1
kind: Pod
name: app1
field:
path: spec.containers.image
currentValue: nginx:1.20.2
proposedValue: bitnami/nginx:1.21.4
file:
path: app.yaml
- message: set image from nginx:1.20.2 to bitnami/nginx:1.21.4
- message: updated image from nginx:1.20.2 to bitnami/nginx:1.21.4
severity: info
resourceRef:
apiVersion: v1
kind: Pod
name: app2
field:
path: spec.containers.image
currentValue: nginx:1.20.2
proposedValue: bitnami/nginx:1.21.4
file:
path: app.yaml
index: 1
- message: 'summary: updated a total of 2 image(s)'
severity: info
14 changes: 4 additions & 10 deletions examples/set-image-simple/.expected/results.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,22 @@ items:
- image: gcr.io/kpt-fn/set-image:unstable
exitCode: 0
results:
- message: set image from nginx:1.20.2 to bitnami/nginx:1.21.4
- message: updated image from nginx:1.20.2 to bitnami/nginx:1.21.4
severity: info
resourceRef:
apiVersion: v1
kind: Pod
name: app1
field:
path: spec.containers.image
currentValue: nginx:1.20.2
proposedValue: bitnami/nginx:1.21.4
file:
path: resources.yaml
- message: set image from nginx:1.20.2 to bitnami/nginx:1.21.4
- message: updated image from nginx:1.20.2 to bitnami/nginx:1.21.4
severity: info
resourceRef:
apiVersion: v1
kind: Pod
name: app2
field:
path: spec.containers.image
currentValue: nginx:1.20.2
proposedValue: bitnami/nginx:1.21.4
file:
path: resources.yaml
index: 1
- message: 'summary: updated a total of 2 image(s)'
severity: info
65 changes: 65 additions & 0 deletions functions/go/set-image/custom/custom.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package custom

import (
"fmt"

"github.com/GoogleContainerTools/kpt-functions-sdk/go/fn"
"sigs.k8s.io/kustomize/api/filters/imagetag"
"sigs.k8s.io/kustomize/api/types"
"sigs.k8s.io/kustomize/kyaml/filtersutil"
"sigs.k8s.io/kustomize/kyaml/yaml"
)

// SetAdditionalFieldSpec updates the image in user given fieldPaths. To be deprecated in around a year, to avoid possible invalid fieldPaths.
func SetAdditionalFieldSpec(img *fn.SubObject, objects fn.KubeObjects, addImgFields fn.SliceSubObjects, ctx *fn.Context) {
image := NewImageAdaptor(img)
additionalImageFields := NewFieldSpecSliceAdaptor(addImgFields)

for i, obj := range objects {
objRN, err := yaml.Parse(obj.String())
if err != nil {
ctx.ResultErr(err.Error(), obj)
}
filter := imagetag.Filter{
ImageTag: image,
FsSlice: additionalImageFields,
}

filter.WithMutationTracker(logResultCallback(ctx, obj))
err = filtersutil.ApplyToJSON(filter, objRN)
if err != nil {
ctx.ResultErr(err.Error(), obj)
}
newObj, err := fn.ParseKubeObject([]byte(objRN.MustString()))
if err != nil {
ctx.ResultErr(err.Error(), obj)
}
objects[i] = newObj
}
}

func logResultCallback(ctx *fn.Context, ko *fn.KubeObject) func(key, value, tag string, node *yaml.RNode) {
return func(key, value, tag string, node *yaml.RNode) {
currentValue := node.YNode().Value
msg := fmt.Sprintf("updated image from %v to %v", currentValue, value)
ctx.ResultInfo(msg, ko)
}
}

// NewImageAdaptor transforms the image struct inside transformer to the struct inside kustomize
func NewImageAdaptor(imgObj *fn.SubObject) types.Image {
imgPtr := &types.Image{}
imgObj.AsOrDie(imgPtr)
return *imgPtr
}

// NewFieldSpecSliceAdaptor transforms the additionalImageFields struct inside transformer to the struct inside kustomize
func NewFieldSpecSliceAdaptor(addImgFields fn.SliceSubObjects) types.FsSlice {
additionalImageFields := types.FsSlice{}
for _, v := range addImgFields {
fieldPtr := &types.FieldSpec{}
v.AsOrDie(fieldPtr)
additionalImageFields = append(additionalImageFields, *fieldPtr)
}
return additionalImageFields
}
37 changes: 20 additions & 17 deletions functions/go/set-image/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,34 @@ module github.com/GoogleContainerTools/kpt-functions-catalog/functions/go/set-im
go 1.17

require (
github.com/GoogleContainerTools/kpt-functions-sdk/go/fn v0.0.0-20220503232936-7ad5b77727ee
github.com/stretchr/testify v1.7.0
github.com/GoogleContainerTools/kpt-functions-sdk/go/fn v0.0.0-20220812180116-970f3e4cbc5a
github.com/stretchr/testify v1.8.0
sigs.k8s.io/kustomize/api v0.11.0
sigs.k8s.io/kustomize/kyaml v0.13.6
sigs.k8s.io/kustomize/kyaml v0.13.9
)

require (
github.com/PuerkitoBio/purell v1.1.1 // indirect
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
github.com/GoogleContainerTools/kpt-functions-sdk/go/api v0.0.0-20220812180116-970f3e4cbc5a // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/go-errors/errors v1.0.1 // indirect
github.com/go-logr/logr v1.2.0 // indirect
github.com/go-errors/errors v1.4.2 // indirect
github.com/go-logr/logr v1.2.3 // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/jsonreference v0.19.3 // indirect
github.com/go-openapi/swag v0.19.5 // indirect
github.com/mailru/easyjson v0.7.0 // indirect
github.com/go-openapi/jsonreference v0.20.0 // indirect
github.com/go-openapi/swag v0.22.0 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/gnostic v0.6.9 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/kr/pretty v0.2.1 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/xlab/treeprint v0.0.0-20181112141820-a009c3971eca // indirect
golang.org/x/net v0.0.0-20211209124913-491a49abca63 // indirect
golang.org/x/text v0.3.7 // indirect
github.com/xlab/treeprint v1.1.0 // indirect
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
k8s.io/klog/v2 v2.30.0 // indirect
k8s.io/kube-openapi v0.0.0-20211115234752-e816edb12b65 // indirect
sigs.k8s.io/yaml v1.2.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/klog/v2 v2.70.1 // indirect
k8s.io/kube-openapi v0.0.0-20220803164354-a70c9af30aea // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
)
Loading