-
Notifications
You must be signed in to change notification settings - Fork 450
OCPBUGS-66251: OADP restore results in htpasswd no longer being applied as volume #7628
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
Open
mehabhalodiya
wants to merge
1
commit into
openshift:main
Choose a base branch
from
mehabhalodiya:oadp-oauth
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+178
−0
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
140 changes: 140 additions & 0 deletions
140
control-plane-operator/controllers/hostedcontrolplane/v2/oauth/deployment_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,140 @@ | ||
| package oauth | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| . "github.com/onsi/gomega" | ||
|
|
||
| appsv1 "k8s.io/api/apps/v1" | ||
| corev1 "k8s.io/api/core/v1" | ||
| ) | ||
|
|
||
| // TestRemoveIDPVolumes verifies that removeIDPVolumes filters out only IDP-related volumes | ||
| // while keeping all other volumes intact. | ||
| func TestRemoveIDPVolumes(t *testing.T) { | ||
| t.Run("When deployment has mixed IDP and non-IDP volumes, it should keep only non-IDP volumes", func(t *testing.T) { | ||
| g := NewWithT(t) | ||
|
|
||
| deployment := &appsv1.Deployment{ | ||
| Spec: appsv1.DeploymentSpec{ | ||
| Template: corev1.PodTemplateSpec{ | ||
| Spec: corev1.PodSpec{ | ||
| Volumes: []corev1.Volume{ | ||
| {Name: "idp-secret-0-file-data"}, | ||
| {Name: "idp-cm-0-ca"}, | ||
| {Name: "non-idp-volume"}, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| removeIDPVolumes(deployment) | ||
|
|
||
| g.Expect(deployment.Spec.Template.Spec.Volumes).To(HaveLen(1)) | ||
| g.Expect(deployment.Spec.Template.Spec.Volumes[0].Name).To(Equal("non-idp-volume")) | ||
| }) | ||
|
|
||
| t.Run("When deployment has no IDP volumes, it should keep all volumes unchanged", func(t *testing.T) { | ||
| g := NewWithT(t) | ||
|
|
||
| deployment := &appsv1.Deployment{ | ||
| Spec: appsv1.DeploymentSpec{ | ||
| Template: corev1.PodTemplateSpec{ | ||
| Spec: corev1.PodSpec{ | ||
| Volumes: []corev1.Volume{ | ||
| {Name: "config-volume"}, | ||
| {Name: "audit-config"}, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| removeIDPVolumes(deployment) | ||
|
|
||
| g.Expect(deployment.Spec.Template.Spec.Volumes).To(HaveLen(2)) | ||
| g.Expect(deployment.Spec.Template.Spec.Volumes[0].Name).To(Equal("config-volume")) | ||
| g.Expect(deployment.Spec.Template.Spec.Volumes[1].Name).To(Equal("audit-config")) | ||
| }) | ||
| } | ||
|
|
||
| // TestRemoveIDPVolumeMounts verifies that removeIDPVolumeMounts filters out only IDP-related | ||
| // volume mounts from the oauth-openshift container while keeping all other mounts intact. | ||
| func TestRemoveIDPVolumeMounts(t *testing.T) { | ||
| t.Run("When container has mixed IDP and non-IDP volume mounts, it should keep only non-IDP mounts", func(t *testing.T) { | ||
| g := NewWithT(t) | ||
|
|
||
| deployment := &appsv1.Deployment{ | ||
| Spec: appsv1.DeploymentSpec{ | ||
| Template: corev1.PodTemplateSpec{ | ||
| Spec: corev1.PodSpec{ | ||
| Containers: []corev1.Container{ | ||
| { | ||
| Name: ComponentName, | ||
| VolumeMounts: []corev1.VolumeMount{ | ||
| {Name: "idp-secret-0-file-data"}, | ||
| {Name: "idp-cm-0-ca"}, | ||
| {Name: "config-volume"}, | ||
| }, | ||
| }, | ||
| { | ||
| // Another container to ensure we only filter the oauth-openshift container | ||
| Name: "sidecar", | ||
| VolumeMounts: []corev1.VolumeMount{ | ||
| {Name: "idp-secret-0-file-data"}, | ||
| {Name: "sidecar-volume"}, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| removeIDPVolumeMounts(deployment) | ||
|
|
||
| containers := deployment.Spec.Template.Spec.Containers | ||
| g.Expect(containers).To(HaveLen(2)) | ||
|
|
||
| // oauth-openshift container should have only non-IDP mounts | ||
| oauthMounts := containers[0].VolumeMounts | ||
| g.Expect(oauthMounts).To(HaveLen(1)) | ||
| g.Expect(oauthMounts[0].Name).To(Equal("config-volume")) | ||
|
|
||
| // sidecar container mounts should be untouched | ||
| sidecarMounts := containers[1].VolumeMounts | ||
| g.Expect(sidecarMounts).To(HaveLen(2)) | ||
| g.Expect(sidecarMounts[0].Name).To(Equal("idp-secret-0-file-data")) | ||
| g.Expect(sidecarMounts[1].Name).To(Equal("sidecar-volume")) | ||
| }) | ||
|
|
||
| t.Run("When oauth-openshift container has no IDP mounts, it should keep all mounts unchanged", func(t *testing.T) { | ||
| g := NewWithT(t) | ||
|
|
||
| deployment := &appsv1.Deployment{ | ||
| Spec: appsv1.DeploymentSpec{ | ||
| Template: corev1.PodTemplateSpec{ | ||
| Spec: corev1.PodSpec{ | ||
| Containers: []corev1.Container{ | ||
| { | ||
| Name: ComponentName, | ||
| VolumeMounts: []corev1.VolumeMount{ | ||
| {Name: "config-volume"}, | ||
| {Name: "audit-config"}, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| removeIDPVolumeMounts(deployment) | ||
|
|
||
| oauthMounts := deployment.Spec.Template.Spec.Containers[0].VolumeMounts | ||
| g.Expect(oauthMounts).To(HaveLen(2)) | ||
| g.Expect(oauthMounts[0].Name).To(Equal("config-volume")) | ||
| g.Expect(oauthMounts[1].Name).To(Equal("audit-config")) | ||
| }) | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 doesn't do anything. The deployment object passed to the adapt func is coming from the static manifest file https://github.com/openshift/hypershift/blob/main/control-plane-operator/controllers/hostedcontrolplane/v2/assets/oauth-openshift/deployment.yaml
the code is already idempotent