-
Notifications
You must be signed in to change notification settings - Fork 10
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
Webhook for default images #25
Webhook for default images #25
Conversation
Skipping CI for Draft Pull Request. |
89a5223
to
2281d74
Compare
containerImage: | ||
description: The service specific Container Image URL (will be set | ||
to environmental default if empty) | ||
type: string |
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.
Does the outer/umbrella Watcher
CRD have an image itself? Isn't it only the sub-CR that actually have images?
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.
Nope, Watcher CRD does not have image. Nice catch, let me remove that.
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.
Done!
f99f490
to
a6bef3b
Compare
api/v1beta1/common_types.go
Outdated
|
||
// +kubebuilder:validation:Optional | ||
// The service specific Container Image URL (will be set to environmental default if empty) | ||
ContainerImage string `json:"containerImage"` |
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.
WatcherCommon is used in all CRDs, included Watcher, but Watcher should not have ContainerImage, but WatcherImages. ContainerImage should go out of WatcherCommon, we may create another struct for the params that go to the 2nd level CRs but not to Watcher, or add it to them directly.
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.
Done! Added WatcherContainerImages struct to achieve the same.
api/v1beta1/common_types.go
Outdated
DecisionEngineContainerImageURL string `json:"decisionengineContainerImageURL"` | ||
|
||
// +kubebuilder:validation:Required | ||
// DecisionEngineContainerImageURL |
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.
This should be ApplierContainerImageURL ?
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.
Done!
- name: manager | ||
env: | ||
- name: WATCHER_API_IMAGE_URL_DEFAULT | ||
value: quay.io/tripleozedcentos9/openstack-watcher-api:current-tripleo |
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.
zed ?
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.
Done!
api/v1beta1/common_types.go
Outdated
watcherDefaults := WatcherDefaults{ | ||
APIContainerImageURL: GetEnvDefault("WATCHER_API_IMAGE_URL_DEFAULT", WatcherAPIContainerImage), | ||
ApplierContainerImageURL: GetEnvDefault("WATCHER_APPLIER_IMAGE_URL_DEFAULT", WatcherApplierContainerImage), | ||
DecisionEngineContainerImageURL: GetEnvDefault("WATCHER_DECISION_ENGINE_IMAGE_URI_DEFAULT", WatcherDecisionEngineContainerImage), |
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.
Should be WATCHER_DECISION_ENGINE_IMAGE_URL_DEFAULT? note URI vs URL
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.
Done!
1ade9c2
to
4c34279
Compare
Build failed (check pipeline). Post https://softwarefactory-project.io/zuul/t/rdoproject.org/buildset/365c81644381478b8dca6aec12116be4 ✔️ noop SUCCESS in 0s |
4c34279
to
3d0e2fc
Compare
Build failed (check pipeline). Post https://softwarefactory-project.io/zuul/t/rdoproject.org/buildset/6bfe287af7c046fdad51d643d5c4eef0 ✔️ noop SUCCESS in 0s |
3d0e2fc
to
0f47ba0
Compare
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.
It works well in my local test but I'd suggest to improve the test coverage.
Also fix the default values set in env variables (see my comments).
- name: manager | ||
env: | ||
- name: WATCHER_API_IMAGE_URL_DEFAULT | ||
value: quay.io/tripleoantelopecentos9/openstack-watcher-api:current-tripleo |
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.
Should be pulled from quay.io/podified-antelope-centos9 with current-podified tag:
quay.io/podified-antelope-centos9/openstack-watcher-api:current-podified
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.
Done!
- name: WATCHER_API_IMAGE_URL_DEFAULT | ||
value: quay.io/tripleoantelopecentos9/openstack-watcher-api:current-tripleo | ||
- name: WATCHER_DECISION_ENGINE_IMAGE_URL_DEFAULT | ||
value: quay.io/tripleoantelopecentos9/openstack-watcher-decision-engine:current-tripleo |
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.
ditto
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.
Done!
- name: WATCHER_DECISION_ENGINE_IMAGE_URL_DEFAULT | ||
value: quay.io/tripleoantelopecentos9/openstack-watcher-decision-engine:current-tripleo | ||
- name: WATCHER_APPLIER_IMAGE_URL_DEFAULT | ||
value: quay.io/tripleoantelopecentos9/openstack-watcher-applier:current-tripleo |
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.
ditto
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.
Done!
api/v1beta1/common_types.go
Outdated
@@ -64,3 +73,54 @@ type PasswordSelector struct { | |||
// Service - Selector to get the watcher service user password from the Secret | |||
Service string `json:"service"` | |||
} | |||
|
|||
// WatcherContainerImages | |||
type WatcherContainerImages struct { |
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 have the doubt if we should generalize this more as it may be good to use it for other common parameters for all the 2nd level CRs but not in the initial one. It could be something like WatcherSubCrsCommon ?
I'm not sure if having a reusable struct for only one parameter makes sense.
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.
We will see it in future if we can add more params there.
@@ -371,4 +372,31 @@ var _ = Describe("Watcher controller", func() { | |||
}) | |||
}) | |||
|
|||
When("Watcher CR is created without container images defined", func() { |
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.
We may use any of the existing cases for this tests, i.e. When("A Watcher instance is created from minimal spec").
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.
Done!
Expect(Watcher.Spec.APIContainerImageURL).To(Equal(util.GetEnvVar("RELATED_IMAGE_WATCHER_API_IMAGE_URL_DEFAULT", watcherv1beta1.WatcherAPIContainerImage))) | ||
Expect(Watcher.Spec.DecisionEngineContainerImageURL).To(Equal(util.GetEnvVar("RELATED_IMAGE_WATCHER_DECISION_ENGINE_IMAGE_URL_DEFAULT", watcherv1beta1.WatcherDecisionEngineContainerImage))) | ||
Expect(Watcher.Spec.ApplierContainerImageURL).To(Equal(util.GetEnvVar("RELATED_IMAGE_WATCHER_APPLIER_IMAGE_URL_DEFAULT", watcherv1beta1.WatcherApplierContainerImage))) |
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.
IMO we should run three different cases to fully cover the defaulting functionality:
- No container images defined and no env variable defined. Spec values should == watcherv1beta1.WatcherApplierContainerImage
- No container images defined ane env variable defined to some fake values (this will require a different When case). Spec values should == util.GetEnvVar("RELATED_IMAGE_WATCHER_APPLIER_IMAGE_URL_DEFAULT")
- When Watcher is created with container images values in the spec, Spec values should == to the defined ones (This will also required a different When case to set a different spec).
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.
@amoralej I need help on 3rd option, I am not sure i have done it correctly. https://github.com/raukadah/watcher-operator/blob/webhook_default_images/tests/functional/watcher_controller_test.go#L70 Please have a look.
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'd say that's incorrect as you are modifying the spec after the reconcile loop is finised. I think you need to:
- Add a new spec in addition to MinimalWatcherSpec with your fake values for the images. Something like:
- Define an entirely new test watcher deployment using something similar to:
but instead of using MinimalWatcherSpec you need to use yours.
- Check the values as in:
Note all this has to go into a new When block after the existing one, i.e. after
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.
Actually, Case 2 (getting defaults from env values) also need some rework from https://github.com/raukadah/watcher-operator/blob/webhook_default_images/tests/functional/watcher_controller_test.go#L63-L68 , but I'm not sure how to inject env values for a specific test in envtest. Unless we find a way we may need to skip that case from functional test coverage.
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.
Thank you @amoralej for the detailed writeup. Here is what I have implemented for testcase 3: https://github.com/raukadah/watcher-operator/blob/webhook_default_images/tests/functional/watcher_controller_test.go#L413
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.
For second case, I tried to go via this https://github.com/raukadah/watcher-operator/blob/webhook_default_images/tests/functional/watcher_controller_test.go#L390 Not sure how much it is correct.
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 think you are going in the right path, but i'm adding some suggestions.
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.
spent some time looking though this and trying to follow along
can you bring this to one of the team calls and give some overview of the changes it would be helpful at least for me (eg the last comments/discussion with amoralej about the defaulting)
0f47ba0
to
7e064bd
Compare
Build failed (check pipeline). Post https://softwarefactory-project.io/zuul/t/rdoproject.org/buildset/ceae0842f22540619faa29e080127b71 ✔️ noop SUCCESS in 0s |
9a1bb64
to
80f2871
Compare
|
||
It("should have the Spec fields with above environment container images", func() { | ||
Watcher := GetWatcher(watcherTest.Instance) | ||
Expect(Watcher.Spec.APIContainerImageURL).To(Equal(util.GetEnvVar("RELATED_IMAGE_WATCHER_API_IMAGE_URL_DEFAULT", watcherv1beta1.WatcherAPIContainerImage))) |
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.
In this case we should ensure it has the value of the env variable, while GetEnvVar can take default value. I'd simplify by doing:
Expect(Watcher.Spec.APIContainerImageURL).To(Equal("watcher-api-custom-image"))
And similar for the other two images.
If we want to make sure the values come from env variables, as mentioned, i would use some different value as "watcher-api-custom-image-env" and check it.
BeforeEach(func() { | ||
DeferCleanup(th.DeleteInstance, CreateWatcher(watcherTest.Instance, MinimalWatcherContainerSpec)) | ||
// Set environment variables | ||
os.Setenv("RELATED_IMAGE_WATCHER_API_IMAGE_URL_DEFAULT", "watcher-api-custom-image") |
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.
You are setting the same values in env variables that the ones on MinimalWatcherContainerSpec so in this case to guess if the real parameter is coming from env variable or from the spec. I'd set different values for env (mabye adding -env or something.)
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.
Done
@@ -371,4 +387,32 @@ var _ = Describe("Watcher controller", func() { | |||
}) | |||
}) | |||
|
|||
When("Watcher is created with no container images defined and env variables contains fake value", func() { |
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.
It says "no container images defined and env variables contains fake value" but actually, you are using MinimalWatcherContainerSpec which defines images in the Spec parameters. So we have two options:
- If we want to check that the resulting Watcher get the values from env variables when it's CRs do not includes images you need to CreateWatcher using MinimalWatcherSpec instead of MinimalWatcherContainerSpec.
- If we want to check that the resulting Watcher get the values from CR even if env variables are set (which is what current test would be doing, then i think this should be "Watcher is created with container images defined and env variables contains fake value". In this case the check should be:
It("should have the Spec fields with container images as defined in the CR")
As spec values wins to env variables.
My proposal would be to include these two checks separatedly.
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 failed to achieve the second case so skipping it for now.
Expect(Watcher.Spec.APIContainerImageURL).To(Equal(util.GetEnvVar("RELATED_IMAGE_WATCHER_API_IMAGE_URL_DEFAULT", watcherv1beta1.WatcherAPIContainerImage))) | ||
Expect(Watcher.Spec.DecisionEngineContainerImageURL).To(Equal(util.GetEnvVar("RELATED_IMAGE_WATCHER_DECISION_ENGINE_IMAGE_URL_DEFAULT", watcherv1beta1.WatcherDecisionEngineContainerImage))) | ||
Expect(Watcher.Spec.ApplierContainerImageURL).To(Equal(util.GetEnvVar("RELATED_IMAGE_WATCHER_APPLIER_IMAGE_URL_DEFAULT", watcherv1beta1.WatcherApplierContainerImage))) |
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 think you are going in the right path, but i'm adding some suggestions.
@@ -52,6 +61,13 @@ var _ = Describe("Watcher controller with minimal spec values", func() { | |||
}, timeout, interval).Should(ContainElement("openstack.org/watcher")) | |||
}) | |||
|
|||
It("It has the expected container image defaults", func() { | |||
Watcher := GetWatcher(watcherTest.Instance) | |||
Expect(Watcher.Spec.APIContainerImageURL).To(Equal(util.GetEnvVar("RELATED_IMAGE_WATCHER_API_IMAGE_URL_DEFAULT", watcherv1beta1.WatcherAPIContainerImage))) |
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.
are those *_URL_DEFAULT
vars defined in these tests? I think we should simply use the watcherv1beta1
variables here
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.
Done!
80f2871
to
771002f
Compare
Merge Failed. This change or one of its cross-repo dependencies was unable to be automatically merged with the current state of its repository. Please rebase the change and upload a new patchset. |
771002f
to
4dfe962
Compare
69b0a06
to
0110797
Compare
Build failed (check pipeline). Post https://softwarefactory-project.io/zuul/t/rdoproject.org/buildset/c2ae24b40cfa4baeb6aceb7644fb5d69 ✔️ noop SUCCESS in 0s |
Jira: https://issues.redhat.com/browse/OSPRH-11933 Signed-off-by: Chandan Kumar <[email protected]>
0110797
to
945d8bf
Compare
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.
thanks for the changes Chandan, lgtm
/aprove |
/approve |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: amoralej The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
0930858
into
openstack-k8s-operators:main
Jira: https://issues.redhat.com/browse/OSPRH-11933