This repository has been archived by the owner on Jun 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 47
Validating dataplane/controlplane TLS consistency #821
Open
jpodivin
wants to merge
1
commit into
openstack-k8s-operators:main
Choose a base branch
from
jpodivin:tlsplanes
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.
+504
−4
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
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -17,9 +17,11 @@ limitations under the License. | |
package v1beta1 | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"golang.org/x/exp/slices" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
|
||
infranetworkv1 "github.com/openstack-k8s-operators/infra-operator/apis/network/v1beta1" | ||
condition "github.com/openstack-k8s-operators/lib-common/modules/common/condition" | ||
|
@@ -290,3 +292,49 @@ func (r *OpenStackDataPlaneNodeSetSpec) duplicateNodeCheck(nodeSetList *OpenStac | |
|
||
return | ||
} | ||
|
||
// Compare TLS settings of control plane and data plane | ||
// if control plane name is specified attempt to retrieve it | ||
// otherwise get any control plane in the namespace | ||
func (r *OpenStackDataPlaneNodeSetSpec) ValidateTLS(namespace string, reconcilerClient client.Client, ctx context.Context) error { | ||
var err error | ||
controlPlanes := openstackv1.OpenStackControlPlaneList{} | ||
opts := client.ListOptions{ | ||
Namespace: namespace, | ||
} | ||
|
||
// Attempt to get list of all ControlPlanes fail if that isn't possible | ||
if err = reconcilerClient.List(ctx, &controlPlanes, &opts); err != nil { | ||
return err | ||
} | ||
// Verify TLS status of control plane only if there is a single one | ||
// report error if there are multiple, or proceed if there are none | ||
if len(controlPlanes.Items) > 1 { | ||
err = fmt.Errorf("multiple control planes found in the namespace %s", namespace) | ||
} else if len(controlPlanes.Items) == 1 { | ||
controlPlane := controlPlanes.Items[0] | ||
fieldErr := r.TLSMatch(controlPlane) | ||
if fieldErr != nil { | ||
err = fmt.Errorf("%s", fieldErr.Error()) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again, if there is no control plane , we should requeue and wait, right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto |
||
} | ||
|
||
return err | ||
} | ||
|
||
// Do TLS flags match in control plane ingress, pods and data plane | ||
func (r *OpenStackDataPlaneNodeSetSpec) TLSMatch(controlPlane openstackv1.OpenStackControlPlane) *field.Error { | ||
|
||
if controlPlane.Spec.TLS.Ingress.Enabled != r.TLSEnabled || controlPlane.Spec.TLS.PodLevel.Enabled != r.TLSEnabled { | ||
|
||
return field.Forbidden( | ||
field.NewPath("spec.tlsEnabled"), | ||
fmt.Sprintf( | ||
"TLS settings on Data Plane node set and Control Plane %s do not match, Node set: %t Control Plane Ingress: %t Control Plane PodLevel: %t", | ||
controlPlane.Name, | ||
r.TLSEnabled, | ||
controlPlane.Spec.TLS.Ingress.Enabled, | ||
controlPlane.Spec.TLS.PodLevel.Enabled)) | ||
} | ||
return nil | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.
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.
In the case where the control plane is not found, we should requeue and wait, right?
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.
Based on your comments in JIRA I though we want to ignore this case and continue uninterrupted?
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.
ah good point. I forgot about the no control plane case. @slagle - this is a legit case, right?