diff --git a/deploy/crds/atlassian.com_nodegroups_crd.yaml b/deploy/crds/atlassian.com_nodegroups_crd.yaml index d75ee73..b537504 100644 --- a/deploy/crds/atlassian.com_nodegroups_crd.yaml +++ b/deploy/crds/atlassian.com_nodegroups_crd.yaml @@ -311,6 +311,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 diff --git a/docs/automation/README.md b/docs/automation/README.md index 292ca21..b793f8b 100644 --- a/docs/automation/README.md +++ b/docs/automation/README.md @@ -34,6 +34,8 @@ spec: cycleSettings: method: Drain concurrency: 1 + validationOptions: + skipMissingNamedNodes: true healthChecks: - endpoint: http://{{ .NodeIP }}:8080/ready regexMatch: Ready diff --git a/docs/cycling/README.md b/docs/cycling/README.md index e17cfcf..4f374e9 100644 --- a/docs/cycling/README.md +++ b/docs/cycling/README.md @@ -106,6 +106,11 @@ spec: - "node-name-A" - "node-name-B" + # Optional section - collection of validation options to define stricter or more lenient validation during cycling. + validationOptions: + # Optional field - Skip node names defined in the CNR that do not match any existing nodes in the Kubernetes API. + skipMissingNamedNodes: true|false + cycleNodeSettings: # Method can be "Wait" or "Drain", defaults to "Drain" if not provided # "Wait" will wait for pods on the node to complete, while "Drain" will forcefully drain them off the node diff --git a/pkg/apis/atlassian/v1/common_types.go b/pkg/apis/atlassian/v1/common_types.go index 09236dc..181cea6 100644 --- a/pkg/apis/atlassian/v1/common_types.go +++ b/pkg/apis/atlassian/v1/common_types.go @@ -104,3 +104,12 @@ type TLSConfig struct { // sent as part of the request to the upstream host for mTLS. Key string `json:"key,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"` +} diff --git a/pkg/apis/atlassian/v1/cyclenoderequest_types.go b/pkg/apis/atlassian/v1/cyclenoderequest_types.go index 5d13c74..867fabd 100644 --- a/pkg/apis/atlassian/v1/cyclenoderequest_types.go +++ b/pkg/apis/atlassian/v1/cyclenoderequest_types.go @@ -111,15 +111,6 @@ 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" diff --git a/pkg/apis/atlassian/v1/nodegroup_types.go b/pkg/apis/atlassian/v1/nodegroup_types.go index 52d4c69..9d0e0e0 100644 --- a/pkg/apis/atlassian/v1/nodegroup_types.go +++ b/pkg/apis/atlassian/v1/nodegroup_types.go @@ -19,6 +19,10 @@ type NodeGroupSpec 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"` diff --git a/pkg/apis/atlassian/v1/zz_generated.deepcopy.go b/pkg/apis/atlassian/v1/zz_generated.deepcopy.go index 09dfe35..dbc0e9d 100644 --- a/pkg/apis/atlassian/v1/zz_generated.deepcopy.go +++ b/pkg/apis/atlassian/v1/zz_generated.deepcopy.go @@ -462,6 +462,7 @@ func (in *NodeGroupSpec) DeepCopyInto(out *NodeGroupSpec) { } in.NodeSelector.DeepCopyInto(&out.NodeSelector) in.CycleSettings.DeepCopyInto(&out.CycleSettings) + out.ValidationOptions = in.ValidationOptions if in.HealthChecks != nil { in, out := &in.HealthChecks, &out.HealthChecks *out = make([]HealthCheck, len(*in)) diff --git a/pkg/generation/cnr.go b/pkg/generation/cnr.go index 9808b93..db5615d 100644 --- a/pkg/generation/cnr.go +++ b/pkg/generation/cnr.go @@ -3,9 +3,10 @@ package generation import ( "context" "fmt" - "github.com/atlassian-labs/cyclops/pkg/controller/cyclenoderequest" "strings" + "github.com/atlassian-labs/cyclops/pkg/controller/cyclenoderequest" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/validation" "sigs.k8s.io/controller-runtime/pkg/client" @@ -73,8 +74,9 @@ func GiveReason(cnr *atlassianv1.CycleNodeRequest, reason string) { } cnr.Annotations[cnrReasonAnnotationKey] = reason } + // SetAPIVersion adds apiVersion annotation to the cnr -func SetAPIVersion(cnr *atlassianv1.CycleNodeRequest, clientVersion string){ +func SetAPIVersion(cnr *atlassianv1.CycleNodeRequest, clientVersion string) { if cnr.Annotations == nil { cnr.Annotations = map[string]string{} } @@ -110,6 +112,7 @@ func GenerateCNR(nodeGroup atlassianv1.NodeGroup, nodes []string, name, namespac PreTerminationChecks: nodeGroup.Spec.PreTerminationChecks, SkipInitialHealthChecks: nodeGroup.Spec.SkipInitialHealthChecks, SkipPreTerminationChecks: nodeGroup.Spec.SkipPreTerminationChecks, + ValidationOptions: nodeGroup.Spec.ValidationOptions, }, } }