From 6ed12871f931492ab40de2dcfc1070a0131cfbe1 Mon Sep 17 00:00:00 2001 From: Philippe Martin Date: Thu, 15 Dec 2022 13:11:05 +0100 Subject: [PATCH] Enable use of ImageStreams on OpenShift (#6406) * Enable use of ImageStreams on OpenShift * Add annotation in examples --- .../docs/development/architecture/how-odo-works.md | 3 +++ pkg/devfile/adapters/kubernetes/component/adapter.go | 1 + pkg/labels/labels.go | 6 ++++++ tests/integration/cmd_dev_test.go | 10 ++++++++++ 4 files changed, 20 insertions(+) diff --git a/docs/website/docs/development/architecture/how-odo-works.md b/docs/website/docs/development/architecture/how-odo-works.md index 8ff1d838dfe..1ef9443ba8a 100644 --- a/docs/website/docs/development/architecture/how-odo-works.md +++ b/docs/website/docs/development/architecture/how-odo-works.md @@ -82,6 +82,7 @@ By default, `odo` adds the following annotations to the Deployment: | Key | Description | Example Value | |----------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------| | `odo.dev/project-type ` | the application runtime, if available. Value is read in order from the `metadata.projectType` or `metadata.language` fields in the Devfile. As both metadata are optional, this annotation can be omitted. | `spring` | +| `alpha.image.policy.openshift.io/resolve-names` | Enable the use of ImageStreams on OpenShift | `*` | Notes: - Any additional annotations defined via the `components[].container.annotation.deployment` field will also be added to this resource. @@ -130,6 +131,7 @@ metadata: name: my-sample-java-springboot-app annotations: # highlight-start + alpha.image.policy.openshift.io/resolve-names: '*' odo.dev/project-type: spring example.com/my-annotation: value-1 # highlight-end @@ -140,6 +142,7 @@ spec: name: my-sample-java-springboot-app annotations: # highlight-start + alpha.image.policy.openshift.io/resolve-names: '*' odo.dev/project-type: spring example.com/my-annotation: value-1 # highlight-end diff --git a/pkg/devfile/adapters/kubernetes/component/adapter.go b/pkg/devfile/adapters/kubernetes/component/adapter.go index d9ffb6d8a68..d7a0b18a6a0 100644 --- a/pkg/devfile/adapters/kubernetes/component/adapter.go +++ b/pkg/devfile/adapters/kubernetes/component/adapter.go @@ -389,6 +389,7 @@ func (a *Adapter) createOrUpdateComponent( annotations := make(map[string]string) odolabels.SetProjectType(annotations, component.GetComponentTypeFromDevfileMetadata(a.AdapterContext.Devfile.Data.GetMetadata())) + odolabels.AddCommonAnnotations(annotations) klog.V(4).Infof("We are deploying these annotations: %s", annotations) containers, err := generator.GetContainers(a.Devfile, parsercommon.DevfileOptions{}) diff --git a/pkg/labels/labels.go b/pkg/labels/labels.go index 6b196201561..8c214a1ccef 100644 --- a/pkg/labels/labels.go +++ b/pkg/labels/labels.go @@ -201,6 +201,12 @@ func SetProjectType(annotations map[string]string, value string) { annotations[odoProjectTypeAnnotation] = value } +func AddCommonAnnotations(annotations map[string]string) { + // Enable use of ImageStreams on OpenShift: + // https://github.com/redhat-developer/odo/issues/6376 + annotations["alpha.image.policy.openshift.io/resolve-names"] = "*" +} + // GetSelector returns a selector string used for selection of resources which are part of the given component in given mode // Note: isPartOfComponent denotes if the selector is required for a core resource(deployment, svc, pvc, pv) of a given component deployed with `odo dev` // it is the only thing that sets it apart from the resources created via other ways (`odo deploy`, deploying resource with apply command during `odo dev`) diff --git a/tests/integration/cmd_dev_test.go b/tests/integration/cmd_dev_test.go index 792e850a55e..25428ba17f4 100644 --- a/tests/integration/cmd_dev_test.go +++ b/tests/integration/cmd_dev_test.go @@ -64,6 +64,16 @@ var _ = Describe("odo dev command tests", func() { helper.Cmd("odo", "init", "--name", cmpName, "--devfile-path", helper.GetExamplePath("source", "devfiles", "nodejs", "devfile.yaml")).ShouldPass() Expect(helper.VerifyFileExists(".odo/env/env.yaml")).To(BeFalse()) }) + + It("should add annotation to use ImageStreams", func() { + // #6376 + err := helper.RunDevMode(nil, nil, func(session *gexec.Session, outContents, errContents []byte, ports map[string]string) { + annotations := commonVar.CliRunner.GetAnnotationsDeployment(cmpName, "app", commonVar.Project) + Expect(annotations["alpha.image.policy.openshift.io/resolve-names"]).To(Equal("*")) + }) + Expect(err).ToNot(HaveOccurred()) + }) + It("should show validation errors if the devfile is incorrect", func() { err := helper.RunDevMode(nil, nil, func(session *gexec.Session, outContents, errContents []byte, ports map[string]string) { helper.ReplaceString(filepath.Join(commonVar.Context, "devfile.yaml"), "kind: run", "kind: build")