Skip to content
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

fix failed tests are depends on external container images #5328

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,11 @@ test-unit-all: \
# This target is used by our Github Actions CI to run unit tests for all non-plugin modules in multiple GOOS environments.
.PHONY: test-unit-non-plugin
test-unit-non-plugin:
./hack/for-each-module.sh "make test" "./plugin/*" 16
./hack/for-each-module.sh "make test" "./plugin/*" 19

.PHONY: build-non-plugin-all
build-non-plugin-all:
./hack/for-each-module.sh "make build" "./plugin/*" 16
./hack/for-each-module.sh "make build" "./plugin/*" 19

.PHONY: test-unit-kustomize-plugins
test-unit-kustomize-plugins:
Expand Down
133 changes: 74 additions & 59 deletions api/krusty/fnplugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ import (
"sigs.k8s.io/kustomize/kyaml/filesys"
)

const (
repoRootDir = "../../"
)

const generateDeploymentDotSh = `#!/bin/sh

cat <<EOF
Expand Down Expand Up @@ -513,51 +517,58 @@ func TestFnContainerGenerator(t *testing.T) {
resources:
- deployment.yaml
generators:
- project-service-set.yaml
- service-set.yaml
`)
// Create generator config
th.WriteF(filepath.Join(tmpDir.String(), "project-service-set.yaml"), `
apiVersion: blueprints.cloud.google.com/v1alpha1
kind: ProjectServiceSet
th.WriteF(filepath.Join(tmpDir.String(), "service-set.yaml"), `
apiVersion: kustomize.sigs.k8s.io/v1alpha1
kind: ServiceGenerator
metadata:
name: demo
name: simplegenerator
annotations:
config.kubernetes.io/function: |
container:
image: gcr.io/kpt-fn/enable-gcp-services:v0.1.0
image: gcr.io/kustomize-functions/e2econtainersimplegenerator
spec:
services:
- compute.googleapis.com
projectID: foo
port: 8081
`)
// Create another resource just to make sure everything is added
th.WriteF(filepath.Join(tmpDir.String(), "deployment.yaml"), `
apiVersion: apps/v1
kind: Deployment
metadata:
name: foo
name: simplegenerator
`)

build := exec.Command("docker", "build", ".",
"-f", "./cmd/config/internal/commands/e2e/e2econtainersimplegenerator/Dockerfile",
"-t", "gcr.io/kustomize-functions/e2econtainersimplegenerator",
)
build.Dir = repoRootDir
assert.NoError(t, build.Run())

m := th.Run(tmpDir.String(), o)
actual, err := m.AsYaml()
assert.NoError(t, err)
assert.Equal(t, `apiVersion: apps/v1
kind: Deployment
metadata:
name: foo
name: simplegenerator
---
apiVersion: serviceusage.cnrm.cloud.google.com/v1beta1
apiVersion: v1
kind: Service
metadata:
annotations:
blueprints.cloud.google.com/ownerReference: blueprints.cloud.google.com/ProjectServiceSet/demo
config.kubernetes.io/function: |
container:
image: gcr.io/kpt-fn/enable-gcp-services:v0.1.0
name: demo-compute
labels:
app: simplegenerator
name: simplegenerator-svc
spec:
projectRef:
external: foo
resourceID: compute.googleapis.com
ports:
- name: http
port: 8081
protocol: TCP
targetPort: 8081
selector:
app: simplegenerator
`, string(actual))
}

Expand Down Expand Up @@ -593,7 +604,7 @@ metadata:
"-f", "./cmd/config/internal/commands/e2e/e2econtainerconfig/Dockerfile",
"-t", "gcr.io/kustomize-functions/e2econtainerconfig",
)
build.Dir = "../../" // Repo root
build.Dir = repoRootDir
assert.NoError(t, build.Run())
m := th.Run(tmpDir.String(), o)
actual, err := m.AsYaml()
Expand All @@ -611,6 +622,12 @@ metadata:

func TestFnContainerTransformerWithConfig(t *testing.T) {
skipIfNoDocker(t)
//https://docs.docker.com/engine/reference/commandline/build/#git-repositories
build := exec.Command("docker", "build", "https://github.com/GoogleContainerTools/kpt-functions-sdk.git#go-sdk-v0.0.1:ts/hello-world",
"-f", "build/label_namespace.Dockerfile",
"-t", "gcr.io/kpt-functions/label-namespace:go-sdk-v0.0.1",
)
assert.NoError(t, build.Run())
th := kusttest_test.MakeHarness(t)
o := th.MakeOptionsPluginsEnabled()
fSys := filesys.MakeFsOnDisk()
Expand Down Expand Up @@ -644,7 +661,7 @@ metadata:
annotations:
config.kubernetes.io/function: |-
container:
image: gcr.io/kpt-functions/label-namespace@sha256:4f030738d6d25a207641ca517916431517578bd0eb8d98a8bde04e3bb9315dcd
image: gcr.io/kpt-functions/label-namespace:go-sdk-v0.0.1
data:
label_name: my-ns-name
label_value: function-test
Expand Down Expand Up @@ -684,25 +701,31 @@ generators:
- gener.yaml
`)))
assert.NoError(t, fSys.WriteFile(filepath.Join(tmpDir.String(), "gener.yaml"), []byte(`
apiVersion: v1
kind: ConfigMap
apiVersion: kustomize.sigs.k8s.io/v1alpha1
kind: EnvTemplateGenerator
metadata:
name: demo
name: e2econtainerenvgenerator
annotations:
config.kubernetes.io/function: |
container:
image: quay.io/aodinokov/kpt-templater:0.0.1
image: gcr.io/kustomize-functions/e2econtainerenvgenerator
envs:
- TESTTEMPLATE=value
data:
template: |
apiVersion: v1
kind: ConfigMap
metadata:
name: env
data:
value: '{{ env "TESTTEMPLATE" }}'
template: |
apiVersion: v1
kind: ConfigMap
metadata:
name: env
data:
value: %q
`)))
build := exec.Command("docker", "build", ".",
"-f", "./cmd/config/internal/commands/e2e/e2econtainerenvgenerator/Dockerfile",
"-t", "gcr.io/kustomize-functions/e2econtainerenvgenerator",
)
build.Dir = repoRootDir
assert.NoError(t, build.Run())

m, err := b.Run(
fSys,
tmpDir.String())
Expand Down Expand Up @@ -731,44 +754,36 @@ generators:
- gener.yaml
`)))
assert.NoError(t, fSys.WriteFile(filepath.Join(tmpDir.String(), "gener.yaml"), []byte(`
apiVersion: v1alpha1
apiVersion: kustomize.sigs.k8s.io/v1alpha1
kind: RenderHelmChart
metadata:
name: demo
annotations:
config.kubernetes.io/function: |
container:
image: gcr.io/kpt-fn/render-helm-chart:v0.1.0
image: gcr.io/kustomize-functions/e2econtainermountbind
mounts:
- type: "bind"
src: "./charts"
dst: "/tmp/charts"
helmCharts:
- name: helloworld-chart
releaseName: test
valuesFile: /tmp/charts/helloworld-values/values.yaml
src: "./yaml"
dst: "/tmp/yaml"
path: /tmp/yaml/resources.yaml
`)))
assert.NoError(t, fSys.MkdirAll(filepath.Join(tmpDir.String(), "charts", "helloworld-chart", "templates")))
assert.NoError(t, fSys.MkdirAll(filepath.Join(tmpDir.String(), "charts", "helloworld-values")))
assert.NoError(t, fSys.WriteFile(filepath.Join(tmpDir.String(), "charts", "helloworld-chart", "Chart.yaml"), []byte(`
apiVersion: v2
name: helloworld-chart
description: A Helm chart for Kubernetes
type: application
version: 0.1.0
appVersion: 1.16.0
`)))
assert.NoError(t, fSys.WriteFile(filepath.Join(tmpDir.String(), "charts", "helloworld-chart", "templates", "deployment.yaml"), []byte(`
assert.NoError(t, fSys.MkdirAll(filepath.Join(tmpDir.String(), "yaml", "tmp")))
assert.NoError(t, fSys.WriteFile(filepath.Join(tmpDir.String(), "yaml", "resources.yaml"), []byte(`
apiVersion: apps/v1
kind: Deployment
metadata:
name: name
spec:
replicas: {{ .Values.replicaCount }}
`)))
assert.NoError(t, fSys.WriteFile(filepath.Join(tmpDir.String(), "charts", "helloworld-values", "values.yaml"), []byte(`
replicaCount: 5
replicas: 3
`)))
build := exec.Command("docker", "build", ".",
"-f", "./cmd/config/internal/commands/e2e/e2econtainermountbind/Dockerfile",
"-t", "gcr.io/kustomize-functions/e2econtainermountbind",
)
build.Dir = repoRootDir
assert.NoError(t, build.Run())

m, err := b.Run(
fSys,
tmpDir.String())
Expand All @@ -780,7 +795,7 @@ kind: Deployment
metadata:
name: name
spec:
replicas: 5
replicas: 3
`, string(actual))
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright 2019 The Kubernetes Authors.
# SPDX-License-Identifier: Apache-2.0

FROM golang:1.20-bullseye
ENV CGO_ENABLED=0
WORKDIR /go/src/

# download modules
# COPY go.mod go.mod
# COPY go.sum go.sum
# RUN go mod download

COPY . .
RUN go build -v -o /usr/local/bin/function ./cmd/config/internal/commands/e2e/e2econtainerenvgenerator

FROM alpine:latest
COPY --from=0 /usr/local/bin/function /usr/local/bin/function
CMD ["function"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Copyright 2019 The Kubernetes Authors.
# SPDX-License-Identifier: Apache-2.0

include ../../../../../../Makefile-modules.mk

.PHONY: image
image:
docker build . -t gcr.io/kustomize-functions/e2econtainerenvgenerator
docker push gcr.io/kustomize-functions/e2econtainerenvgenerator
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Copyright 2019 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0

// Package main contains a function to be used for e2e testing.
// See https://github.com/kubernetes-sigs/kustomize/blob/master/cmd/config/docs/api-conventions/functions-spec.md
package main
34 changes: 34 additions & 0 deletions cmd/config/internal/commands/e2e/e2econtainerenvgenerator/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
module sigs.k8s.io/kustomize/cmd/config/internal/commands/e2e/e2econtainerenvgenerator

go 1.20
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@koba1t Could you elaborate on why we need a separate go mod file and repo for e2e testing? I'm sorry if the question sounds trivial, but I'm still trying to catch up. The issue states:

"I believe this was caused by attempting to run a container image that was built external to this repo and does not support the arm64 architecture."

but I'm just wondering if we need to init a separate repo for just for e2e. And if its just for building the container image, why do we need to do it specifically inside this directory?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @varshaprasad96
Thanks for your comment.

but I'm just wondering if we need to init a separate repo for just for e2e. And if its just for building the container image

I think we need any container images when testing the KRM container function. And, I think we need separate modules because we need to build small images in tests.

why do we need to do it specifically inside this directory?

I'm just putting the same directory on the source of previous e2e tests container image.

If you need any ideas to improve these tests, Could you tell me that?
I want to know your advice and improve this code!


require sigs.k8s.io/kustomize/kyaml v0.14.2

require (
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/go-errors/errors v1.4.2 // indirect
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/swag v0.22.3 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/gnostic-models v0.6.8 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 // indirect
github.com/spf13/cobra v1.7.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/xlab/treeprint v1.2.0 // indirect
golang.org/x/sys v0.13.0 // indirect
google.golang.org/protobuf v1.30.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/kube-openapi v0.0.0-20230601164746-7562a1006961 // indirect
k8s.io/utils v0.0.0-20230505201702-9f6742963106 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
)

replace sigs.k8s.io/kustomize/kyaml => ../../../../../../kyaml
Loading
Loading