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

Webhook for default images #25

Conversation

raukadah
Copy link
Contributor

@raukadah raukadah commented Dec 11, 2024

Copy link

openshift-ci bot commented Dec 11, 2024

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@raukadah raukadah force-pushed the webhook_default_images branch from 89a5223 to 2281d74 Compare December 11, 2024 11:24
Comment on lines 48 to 47
containerImage:
description: The service specific Container Image URL (will be set
to environmental default if empty)
type: string
Copy link

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

@raukadah raukadah force-pushed the webhook_default_images branch 2 times, most recently from f99f490 to a6bef3b Compare December 12, 2024 09:41

// +kubebuilder:validation:Optional
// The service specific Container Image URL (will be set to environmental default if empty)
ContainerImage string `json:"containerImage"`
Copy link
Contributor

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.

Copy link
Contributor Author

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 Show resolved Hide resolved
DecisionEngineContainerImageURL string `json:"decisionengineContainerImageURL"`

// +kubebuilder:validation:Required
// DecisionEngineContainerImageURL
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be ApplierContainerImageURL ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

api/v1beta1/watcher_webhook.go Show resolved Hide resolved
- name: manager
env:
- name: WATCHER_API_IMAGE_URL_DEFAULT
value: quay.io/tripleozedcentos9/openstack-watcher-api:current-tripleo
Copy link
Contributor

Choose a reason for hiding this comment

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

zed ?

Copy link
Contributor Author

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 Show resolved Hide resolved
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),
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

@raukadah raukadah force-pushed the webhook_default_images branch 4 times, most recently from 1ade9c2 to 4c34279 Compare December 16, 2024 11:36
Copy link

Build failed (check pipeline). Post recheck (without leading slash)
to rerun all jobs. Make sure the failure cause has been resolved before
you rerun jobs.

https://softwarefactory-project.io/zuul/t/rdoproject.org/buildset/365c81644381478b8dca6aec12116be4

✔️ noop SUCCESS in 0s
✔️ openstack-meta-content-provider SUCCESS in 1h 24m 34s
✔️ watcher-operator-validation SUCCESS in 1h 14m 17s
watcher-operator-kuttl FAILURE in 35m 01s

@raukadah raukadah force-pushed the webhook_default_images branch from 4c34279 to 3d0e2fc Compare December 17, 2024 07:07
Copy link

Build failed (check pipeline). Post recheck (without leading slash)
to rerun all jobs. Make sure the failure cause has been resolved before
you rerun jobs.

https://softwarefactory-project.io/zuul/t/rdoproject.org/buildset/6bfe287af7c046fdad51d643d5c4eef0

✔️ noop SUCCESS in 0s
✔️ openstack-meta-content-provider SUCCESS in 1h 36m 48s
✔️ watcher-operator-validation SUCCESS in 1h 25m 47s
watcher-operator-kuttl FAILURE in 41m 26s

@raukadah raukadah force-pushed the webhook_default_images branch from 3d0e2fc to 0f47ba0 Compare December 17, 2024 12:40
@raukadah raukadah changed the title [WIP] Webhook for default images Webhook for default images Dec 17, 2024
Copy link
Contributor

@amoralej amoralej left a 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
Copy link
Contributor

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

Copy link
Contributor Author

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
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

Copy link
Contributor Author

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
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

@@ -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 {
Copy link
Contributor

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.

Copy link
Contributor Author

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() {
Copy link
Contributor

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").

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

Comment on lines 396 to 403
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)))
Copy link
Contributor

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:

  1. No container images defined and no env variable defined. Spec values should == watcherv1beta1.WatcherApplierContainerImage
  2. 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")
  3. 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).

Copy link
Contributor Author

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.

Copy link
Contributor

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:

  1. Add a new spec in addition to MinimalWatcherSpec with your fake values for the images. Something like:

https://github.com/raukadah/watcher-operator/blob/webhook_default_images/tests/functional/watcher_controller_test.go#L20-L24

  1. Define an entirely new test watcher deployment using something similar to:

https://github.com/raukadah/watcher-operator/blob/webhook_default_images/tests/functional/watcher_controller_test.go#L27-L31

but instead of using MinimalWatcherSpec you need to use yours.

  1. Check the values as in:

https://github.com/raukadah/watcher-operator/blob/webhook_default_images/tests/functional/watcher_controller_test.go#L32-L40

Note all this has to go into a new When block after the existing one, i.e. after

https://github.com/raukadah/watcher-operator/blob/webhook_default_images/tests/functional/watcher_controller_test.go#L399

Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

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.

Copy link

@marios marios left a 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)

Copy link

Build failed (check pipeline). Post recheck (without leading slash)
to rerun all jobs. Make sure the failure cause has been resolved before
you rerun jobs.

https://softwarefactory-project.io/zuul/t/rdoproject.org/buildset/ceae0842f22540619faa29e080127b71

✔️ noop SUCCESS in 0s
✔️ openstack-meta-content-provider SUCCESS in 1h 56m 39s
✔️ watcher-operator-validation SUCCESS in 1h 28m 29s
watcher-operator-kuttl FAILURE in 43m 03s

@raukadah raukadah force-pushed the webhook_default_images branch 2 times, most recently from 9a1bb64 to 80f2871 Compare December 19, 2024 07:05
@raukadah raukadah marked this pull request as ready for review December 19, 2024 07:05
@openshift-ci openshift-ci bot requested review from cescgina and viroel December 19, 2024 07:05

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)))
Copy link
Contributor

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.

tests/functional/watcher_controller_test.go Show resolved Hide resolved
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")
Copy link
Contributor

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.)

Copy link
Contributor Author

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() {
Copy link
Contributor

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:

  1. 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.
  2. 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.

Copy link
Contributor Author

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.

Comment on lines 396 to 403
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)))
Copy link
Contributor

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)))
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

Copy link

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.
Warning:
Error merging github.com/openstack-k8s-operators/watcher-operator for 25,771002fe67f23238fe499e3c5bdd9b4c1d661e71

@raukadah raukadah force-pushed the webhook_default_images branch from 771002f to 4dfe962 Compare December 19, 2024 13:10
@raukadah raukadah force-pushed the webhook_default_images branch 3 times, most recently from 69b0a06 to 0110797 Compare December 19, 2024 14:03
Copy link

Build failed (check pipeline). Post recheck (without leading slash)
to rerun all jobs. Make sure the failure cause has been resolved before
you rerun jobs.

https://softwarefactory-project.io/zuul/t/rdoproject.org/buildset/c2ae24b40cfa4baeb6aceb7644fb5d69

✔️ noop SUCCESS in 0s
✔️ openstack-meta-content-provider SUCCESS in 2h 10m 32s
✔️ watcher-operator-validation SUCCESS in 1h 27m 41s
watcher-operator-kuttl FAILURE in 41m 07s

@raukadah raukadah force-pushed the webhook_default_images branch from 0110797 to 945d8bf Compare December 20, 2024 06:10
Copy link
Contributor

@cescgina cescgina left a 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

@amoralej
Copy link
Contributor

/aprove

@amoralej
Copy link
Contributor

/approve

Copy link

openshift-ci bot commented Dec 20, 2024

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-merge-bot openshift-merge-bot bot merged commit 0930858 into openstack-k8s-operators:main Dec 20, 2024
6 checks passed
@raukadah raukadah deleted the webhook_default_images branch December 20, 2024 08:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants