Skip to content

Commit

Permalink
Enable use of ImageStreams on OpenShift (#6406)
Browse files Browse the repository at this point in the history
* Enable use of ImageStreams on OpenShift

* Add annotation in examples
  • Loading branch information
feloy authored Dec 15, 2022
1 parent af911dd commit 6ed1287
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 0 deletions.
3 changes: 3 additions & 0 deletions docs/website/docs/development/architecture/how-odo-works.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions pkg/devfile/adapters/kubernetes/component/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{})
Expand Down
6 changes: 6 additions & 0 deletions pkg/labels/labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
Expand Down
10 changes: 10 additions & 0 deletions tests/integration/cmd_dev_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 6ed1287

Please sign in to comment.