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: Add validation method for controller and crd's #5476

Merged
merged 1 commit into from Apr 27, 2023

Conversation

slashpai
Copy link
Contributor

@slashpai slashpai commented Apr 4, 2023

Move controller creation pre-requisites to validation method CheckPrerequisites() to avoid creating
controller object incase of validation failure. This is used for prometheus-agent controller as part of
this commit. These methods can be re-used for future CRD validation
and controllers

This change is result of alert fired during e2e test for prometheus-operator version upgrade in ocp openshift#223. PrometheusOperatorNotReady was fired for prometheus-agent controller since CRD was not installed. Same alert will fire for upstream users who doesn't install prometheus-agent crd. This commit creates agent controller object only when validations are met.

Description

Describe the big picture of your changes here to communicate to the maintainers why we should accept this pull request.
If it fixes a bug or resolves a feature request, be sure to link to that issue.

Type of change

What type of changes does your code introduce to the Prometheus operator? Put an x in the box that apply.

  • CHANGE (fix or feature that would cause existing functionality to not work as expected)
  • FEATURE (non-breaking change which adds functionality)
  • BUGFIX (non-breaking change which fixes an issue)
  • ENHANCEMENT (non-breaking change which improves existing functionality)
  • NONE (if none of the other choices apply. Example, tooling, build system, CI, docs, etc.)

Changelog entry

Please put a one-line changelog entry below. This will be copied to the changelog file during the release process.

Add validation method for controller and crd's and don't create prometheusagent controller incase of validation failure

pkg/prometheus/agent/operator.go Outdated Show resolved Hide resolved
pkg/prometheus/agent/operator.go Outdated Show resolved Hide resolved
cmd/operator/main.go Outdated Show resolved Hide resolved
@xiu xiu mentioned this pull request Apr 11, 2023
5 tasks
@slashpai slashpai force-pushed the agent_validation branch 6 times, most recently from 28bc095 to 5118fee Compare April 12, 2023 09:27
@slashpai
Copy link
Contributor Author

We won't be able to move getMissingPermissions and other methods using operator types to k8sutil package since it creates cyclic dependency. We can move to another package

suggestions?

@slashpai slashpai marked this pull request as ready for review April 13, 2023 05:57
@slashpai slashpai requested a review from a team as a code owner April 13, 2023 05:57
@slashpai
Copy link
Contributor Author

@simonpasquier Can you review when you get chance?

@slashpai
Copy link
Contributor Author

Making a few changes hence moving to draft

@slashpai slashpai marked this pull request as draft April 19, 2023 12:16
@slashpai slashpai force-pushed the agent_validation branch 3 times, most recently from b15d356 to 7b442fa Compare April 19, 2023 12:33
@@ -282,25 +281,6 @@ func New(ctx context.Context, conf operator.Config, logger log.Logger, r prometh

// Run the controller.
func (c *Operator) Run(ctx context.Context) error {
crdInstalled, err := k8sutil.IsAPIGroupVersionResourceSupported(c.kclient.Discovery(), monitoringv1alpha1.SchemeGroupVersion.String(), monitoringv1alpha1.PrometheusAgentName)
Copy link
Contributor Author

@slashpai slashpai Apr 19, 2023

Choose a reason for hiding this comment

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

Moved to k8sutil.CheckPrerequisites()

@@ -1332,44 +1312,3 @@ func (c *Operator) handleMonitorNamespaceUpdate(oldo, curo interface{}) {
)
}
}

// getMissingPermissions returns the RBAC permissions that the controller would need to be
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved to k8sutil

@slashpai slashpai changed the title fix: Add validation method for agent pre-requisite fix: Add validation method for controller and crd's Apr 19, 2023
@slashpai slashpai marked this pull request as ready for review April 19, 2023 12:44
@slashpai
Copy link
Contributor Author

@simonpasquier @JoaoBraveCoding This should be good to review again :)

Copy link
Member

@ArthurSens ArthurSens left a comment

Choose a reason for hiding this comment

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

Brilliant :)

Just a nit

pkg/k8sutil/k8sutil.go Outdated Show resolved Hide resolved
pkg/k8sutil/k8sutil.go Outdated Show resolved Hide resolved
@slashpai slashpai force-pushed the agent_validation branch 2 times, most recently from 37f73c8 to da926b9 Compare April 19, 2023 14:12
@slashpai
Copy link
Contributor Author

Addressed comments and few more fixes :)

Copy link
Contributor

@JoaoBraveCoding JoaoBraveCoding left a comment

Choose a reason for hiding this comment

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

Looks great! Just some small comments

cmd/operator/main.go Outdated Show resolved Hide resolved
pkg/k8sutil/k8sutil.go Outdated Show resolved Hide resolved
pkg/k8sutil/k8sutil.go Outdated Show resolved Hide resolved
cmd/operator/main.go Show resolved Hide resolved
@slashpai slashpai force-pushed the agent_validation branch 3 times, most recently from d6cfa5f to a033063 Compare April 21, 2023 09:26
@slashpai
Copy link
Contributor Author

@JoaoBraveCoding @simonpasquier are we good with the changes? :)

cmd/operator/main.go Outdated Show resolved Hide resolved
cmd/operator/main.go Outdated Show resolved Hide resolved
pkg/k8sutil/k8sutil.go Outdated Show resolved Hide resolved
pkg/k8sutil/k8sutil.go Outdated Show resolved Hide resolved
cmd/operator/main.go Outdated Show resolved Hide resolved
@slashpai slashpai force-pushed the agent_validation branch 2 times, most recently from 3087946 to 91a52d6 Compare April 25, 2023 11:47
pkg/k8sutil/k8sutil.go Outdated Show resolved Hide resolved
pkg/k8sutil/k8sutil.go Outdated Show resolved Hide resolved
pkg/k8sutil/k8sutil.go Outdated Show resolved Hide resolved
pkg/k8sutil/k8sutil.go Outdated Show resolved Hide resolved
pkg/k8sutil/k8sutil.go Outdated Show resolved Hide resolved
pkg/k8sutil/k8sutil.go Outdated Show resolved Hide resolved
pkg/k8sutil/k8sutil.go Outdated Show resolved Hide resolved
pkg/k8sutil/k8sutil.go Outdated Show resolved Hide resolved
pkg/k8sutil/k8sutil.go Outdated Show resolved Hide resolved
cmd/operator/main.go Outdated Show resolved Hide resolved
@slashpai slashpai force-pushed the agent_validation branch 2 times, most recently from 31cb711 to 5086dfa Compare April 26, 2023 10:05
Copy link
Contributor

@JoaoBraveCoding JoaoBraveCoding left a comment

Choose a reason for hiding this comment

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

One small nit but lgtm!

pkg/k8sutil/k8sutil.go Outdated Show resolved Hide resolved
pkg/k8sutil/k8sutil.go Outdated Show resolved Hide resolved
pkg/k8sutil/k8sutil.go Outdated Show resolved Hide resolved
pkg/k8sutil/k8sutil.go Outdated Show resolved Hide resolved
pkg/k8sutil/k8sutil.go Outdated Show resolved Hide resolved
cmd/operator/main.go Outdated Show resolved Hide resolved
cmd/operator/main.go Outdated Show resolved Hide resolved
method `CheckPrerequisites()` to avoid creating
controller object incase of validation failure.

This is used for prometheus-agent controller as part of
this commit.
These methods can be re-used for future CRD validation
and controllers

Signed-off-by: Jayapriya Pai <slashpai9@gmail.com>
@slashpai
Copy link
Contributor Author

@simonpasquier updated 🤞🏻

@simonpasquier simonpasquier merged commit e5cd5c5 into prometheus-operator:main Apr 27, 2023
16 checks passed
@simonpasquier
Copy link
Contributor

thanks!

@rafilkmp3
Copy link

How can I add permission to prometheus agent CRD ? I installed using helm.

@ArthurSens
Copy link
Member

How can I add permission to prometheus agent CRD ? I installed using helm.

The necessary permissions can be seen here. I'm not really familiar how to do so using helm.

Maybe it's worth asking at the helm repository?

@slashpai slashpai deleted the agent_validation branch September 9, 2023 04:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants