Skip to content

Commit

Permalink
Update CNR with new ValidationOptions sub-section
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentportella committed Aug 16, 2024
1 parent 659206b commit 2b6d1db
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 32 deletions.
20 changes: 13 additions & 7 deletions deploy/crds/atlassian.com_cyclenoderequests_crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,6 @@ spec:
- Drain
- Wait
type: string
strictValidation:
description: StrictValidation is a boolean which determines whether
named nodes selected in a CNR must exist and be valid nodes
before cycling can begin. If set to true when invalid nodes
are selected the CNR will be transitioned to the "Failed" phase
before cycling can begin again.
type: boolean
required:
- method
type: object
Expand Down Expand Up @@ -336,6 +329,19 @@ spec:
description: SkipPreTerminationChecks is an optional flag to skip
pre-termination checks during cycling
type: boolean
validationOptions:
description: ValidationOptions stores the settings to use for validating
state of nodegroups in kube and the cloud provider for cycling the
nodes.
properties:
skipMissingNamedNodes:
description: SkipMissingNodeNames is a boolean which determines
whether named nodes selected in a CNR must exist and be valid
nodes before cycling can begin. If set to true named nodes which
don't exist will be ignored rather than transitioning the CNR
to the failed phase.
type: boolean
type: object
required:
- cycleSettings
- nodeGroupName
Expand Down
7 changes: 0 additions & 7 deletions deploy/crds/atlassian.com_cyclenodestatuses_crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,6 @@ spec:
- Drain
- Wait
type: string
strictValidation:
description: StrictValidation is a boolean which determines whether
named nodes selected in a CNR must exist and be valid nodes
before cycling can begin. If set to true when invalid nodes
are selected the CNR will be transitioned to the "Failed" phase
before cycling can begin again.
type: boolean
required:
- method
type: object
Expand Down
7 changes: 0 additions & 7 deletions deploy/crds/atlassian.com_nodegroups_crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,6 @@ spec:
- Drain
- Wait
type: string
strictValidation:
description: StrictValidation is a boolean which determines whether
named nodes selected in a CNR must exist and be valid nodes
before cycling can begin. If set to true when invalid nodes
are selected the CNR will be transitioned to the "Failed" phase
before cycling can begin again.
type: boolean
required:
- method
type: object
Expand Down
5 changes: 0 additions & 5 deletions pkg/apis/atlassian/v1/common_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,6 @@ type CycleSettings struct {
// in-progress CNS request timeout from the time it's worked on by the controller.
// If no cyclingTimeout is provided, CNS will use the default controller CNS cyclingTimeout.
CyclingTimeout *metav1.Duration `json:"cyclingTimeout,omitempty"`

// StrictValidation is a boolean which determines whether named nodes selected in a CNR must
// exist and be valid nodes before cycling can begin. If set to true when invalid nodes are
// selected the CNR will be transitioned to the "Failed" phase before cycling can begin again.
StrictValidation bool `json:"strictValidation,omitempty"`
}

// HealthCheck defines the health check configuration for the NodeGroup
Expand Down
13 changes: 13 additions & 0 deletions pkg/apis/atlassian/v1/cyclenoderequest_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ type CycleNodeRequestSpec struct {
// CycleSettings stores the settings to use for cycling the nodes.
CycleSettings CycleSettings `json:"cycleSettings"`

// ValidationOptions stores the settings to use for validating state of nodegroups
// in kube and the cloud provider for cycling the nodes.
ValidationOptions ValidationOptions `json:"validationOptions,omitempty"`

// HealthChecks stores the settings to configure instance custom health checks
HealthChecks []HealthCheck `json:"healthChecks,omitempty"`

Expand Down Expand Up @@ -107,6 +111,15 @@ type CycleNodeRequestNode struct {
PrivateIP string `json:"privateIp,omitempty"`
}

// ValidationOptions stores the settings to use for validating state of nodegroups
// in kube and the cloud provider for cycling the nodes.
type ValidationOptions struct {
// SkipMissingNodeNames is a boolean which determines whether named nodes selected in a CNR must
// exist and be valid nodes before cycling can begin. If set to true named nodes which don't exist
// will be ignored rather than transitioning the CNR to the failed phase.
SkipMissingNamedNodes bool `json:"skipMissingNamedNodes,omitempty"`
}

// HealthCheckStatus groups all health checks status information for a node
type HealthCheckStatus struct {
// Ready keeps track of the first timestamp at which the node status was reported as "ready"
Expand Down
17 changes: 17 additions & 0 deletions pkg/apis/atlassian/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion pkg/controller/cyclenoderequest/transitioner/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,11 @@ func (t *CycleNodeRequestTransitioner) addNamedNodesToTerminate(kubeNodes map[st
if !found {
t.rm.Logger.Info("could not find node by name, skipping", "nodeName", namedNode)

if t.cycleNodeRequest.Spec.CycleSettings.StrictValidation {
if !t.cycleNodeRequest.Spec.ValidationOptions.SkipMissingNamedNodes {
return fmt.Errorf("could not find node by name: %v", namedNode)
}

t.rm.LogEvent(t.cycleNodeRequest, "SkipMissingNamedNode", "Named node %s not found", namedNode)
continue
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func TestPendingWithNamedNode(t *testing.T) {
// does not match any of the nodes matching the node selector if strict
// validation is not enabled. It will just select the select the nodes that
// exist.
func TestPendingWrongNamedNode(t *testing.T) {
func TestPendingWrongNamedNodeSkipMissingNamedNodes(t *testing.T) {
nodegroup, err := mock.NewNodegroup("ng-1", 2)
if err != nil {
assert.NoError(t, err)
Expand All @@ -131,6 +131,9 @@ func TestPendingWrongNamedNode(t *testing.T) {
Concurrency: 1,
Method: v1.CycleNodeRequestMethodDrain,
},
ValidationOptions: v1.ValidationOptions{
SkipMissingNamedNodes: true,
},
Selector: metav1.LabelSelector{
MatchLabels: map[string]string{
"customer": "kitt",
Expand Down Expand Up @@ -166,7 +169,7 @@ func TestPendingWrongNamedNode(t *testing.T) {
// Test to ensure the Pending phase will reject a CNR with a named node that
// does not match any of the nodes matching the node selector if strict
// validation is enabled. It should error out immediately.
func TestPendingWrongNamedNodeStrictValidation(t *testing.T) {
func TestPendingWrongNamedNode(t *testing.T) {
nodegroup, err := mock.NewNodegroup("ng-1", 2)
if err != nil {
assert.NoError(t, err)
Expand All @@ -180,9 +183,8 @@ func TestPendingWrongNamedNodeStrictValidation(t *testing.T) {
Spec: v1.CycleNodeRequestSpec{
NodeGroupsList: []string{"ng-1"},
CycleSettings: v1.CycleSettings{
Concurrency: 1,
Method: v1.CycleNodeRequestMethodDrain,
StrictValidation: true,
Concurrency: 1,
Method: v1.CycleNodeRequestMethodDrain,
},
Selector: metav1.LabelSelector{
MatchLabels: map[string]string{
Expand Down

0 comments on commit 2b6d1db

Please sign in to comment.