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

Avoid PodSecurityPolicy cleanup if the resource is not supported by Kubernetes API #688

Merged
merged 3 commits into from
Jan 19, 2023

Conversation

levan-m
Copy link
Contributor

@levan-m levan-m commented Jan 17, 2023

What does this PR do?

This change addresses the Kubernetes 1.25 compatibility issue caused by Operator attempting to handle PodDisruptionPolicy resource not available in aforementioned version.

Operator 1.0.0 deployed on v1.25 would log following error on every reconcile

{"level":"ERROR","ts":"2023-01-17T21:19:23Z","logger":"controller.datadogagent","msg":"Reconciler error","reconciler group":"datadoghq.com","reconciler kind":"DatadogAgent","name":"datadog","namespace":"system","error":"no matches for kind \"PodSecurityPolicy\" in version \"policy/v1beta1\"","errorCauses":[{"error":"no matches for kind \"PodSecurityPolicy\" in version \"policy/v1beta1\""}]}

Motivation

Make Operator 1.0.0 run on v1.25.

Additional Notes

This change does not solve PSP usage across Operator.

PSP resource isn't utilized/implemented (see this) and only places attempting to handle PSP were resource cleanup routines. This PR changes the logic producing list of Kinds for the cleanup - it includes PSP only if it's supported by current Kubernetes version.

Once PSP resource implementation is done additional work will be need to control PSP creation.

Describe your test plan

Tested Kubernetes version 1.24, 1.25 using Kind cluster. Deployed agent locally, installed DDA v2 with DCA, CCR enabled - confirmed no errors are thrown.

@levan-m levan-m added the bug Something isn't working label Jan 17, 2023
@levan-m levan-m marked this pull request as ready for review January 17, 2023 22:51
@levan-m levan-m requested review from a team as code owners January 17, 2023 22:51
@CharlyF CharlyF added this to the v1.0.0 milestone Jan 18, 2023
Comment on lines 99 to 100
_, ok1 := platformInfo.apiOtherVersions["PodSecurityPolicy"]
_, ok2 := platformInfo.apiPreferredVersions["PodSecurityPolicy"]
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: can we name these otherExists and preferredExists or something clearer than ok?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated.

@codecov-commenter
Copy link

Codecov Report

Merging #688 (1598727) into main (60eeeca) will increase coverage by 0.11%.
The diff coverage is 80.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #688      +/-   ##
==========================================
+ Coverage   58.53%   58.65%   +0.11%     
==========================================
  Files         149      149              
  Lines       17639    17650      +11     
==========================================
+ Hits        10325    10352      +27     
+ Misses       6700     6682      -18     
- Partials      614      616       +2     
Flag Coverage Δ
unittests 58.65% <80.00%> (+0.11%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
pkg/kubernetes/platforminfo.go 77.27% <66.66%> (-1.68%) ⬇️
controllers/datadogagent/dependencies/store.go 64.08% <100.00%> (ø)
pkg/kubernetes/const.go 87.50% <100.00%> (+87.50%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 60eeeca...1598727. Read the comment docs.

@CharlyF CharlyF merged commit cbeaee3 into main Jan 19, 2023
@CharlyF CharlyF deleted the levan-m/PSP_support branch January 19, 2023 15:06
khewonc pushed a commit that referenced this pull request Jan 20, 2023
…ubernetes API (#688)

* Avoid PodSecurityPolicy cleanup if the resource is not supported by Kubernetes API.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants