Skip to content

Commit

Permalink
Add missing Fields to RosaControlPlane - tags, etcdEncryption
Browse files Browse the repository at this point in the history
Signed-off-by: Xiangjing Li <xiangli@redhat.com>
  • Loading branch information
xiangjingli authored and muraee committed Mar 6, 2024
1 parent f103bff commit be41c4f
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ spec:
spec:
description: RosaControlPlaneSpec defines the desired state of ROSAControlPlane.
properties:
additionalTags:
additionalProperties:
type: string
description: AdditionalTags are user-defined tags to be added on the
AWS resources associated with the control plane.
type: object
autoscaling:
description: Autoscaling specifies auto scaling behaviour for the
MachinePools.
Expand Down Expand Up @@ -102,6 +108,11 @@ spec:
type: string
type: object
x-kubernetes-map-type: atomic
etcdEncryptionKMSArn:
description: EtcdEncryptionKMSArn is the ARN of the KMS key used to
encrypt etcd. The key itself needs to be created out-of-band by
the user and tagged with `red-hat:true`.
type: string
identityRef:
description: IdentityRef is a reference to an identity to be used
when reconciling the managed control plane. If no identity is specified,
Expand Down
9 changes: 9 additions & 0 deletions controlplane/rosa/api/v1beta2/rosacontrolplane_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,15 @@ type RosaControlPlaneSpec struct { //nolint: maligned
// +optional
Autoscaling *expinfrav1.RosaMachinePoolAutoScaling `json:"autoscaling,omitempty"`

// AdditionalTags are user-defined tags to be added on the AWS resources associated with the control plane.
// +optional
AdditionalTags infrav1.Tags `json:"additionalTags,omitempty"`

// EtcdEncryptionKMSArn is the ARN of the KMS key used to encrypt etcd. The key itself needs to be
// created out-of-band by the user and tagged with `red-hat:true`.
// +optional
EtcdEncryptionKMSArn string `json:"etcdEncryptionKMSArn,omitempty"`

// ControlPlaneEndpoint represents the endpoint used to communicate with the control plane.
// +optional
ControlPlaneEndpoint clusterv1.APIEndpoint `json:"controlPlaneEndpoint"`
Expand Down
20 changes: 20 additions & 0 deletions controlplane/rosa/api/v1beta2/rosacontrolplane_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"net"

"github.com/blang/semver"
kmsArnRegexpValidator "github.com/openshift-online/ocm-common/pkg/resource/validations"
apierrors "k8s.io/apimachinery/pkg/api/errors"
runtime "k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/validation/field"
Expand Down Expand Up @@ -33,7 +34,12 @@ func (r *ROSAControlPlane) ValidateCreate() (warnings admission.Warnings, err er
allErrs = append(allErrs, err)
}

if err := r.validateEtcdEncryptionKMSArn(); err != nil {
allErrs = append(allErrs, err)
}

allErrs = append(allErrs, r.validateNetwork()...)
allErrs = append(allErrs, r.Spec.AdditionalTags.Validate()...)

if len(allErrs) == 0 {
return nil, nil
Expand All @@ -54,7 +60,12 @@ func (r *ROSAControlPlane) ValidateUpdate(old runtime.Object) (warnings admissio
allErrs = append(allErrs, err)
}

if err := r.validateEtcdEncryptionKMSArn(); err != nil {
allErrs = append(allErrs, err)
}

allErrs = append(allErrs, r.validateNetwork()...)
allErrs = append(allErrs, r.Spec.AdditionalTags.Validate()...)

if len(allErrs) == 0 {
return nil, nil
Expand Down Expand Up @@ -113,6 +124,15 @@ func (r *ROSAControlPlane) validateNetwork() field.ErrorList {
return allErrs
}

func (r *ROSAControlPlane) validateEtcdEncryptionKMSArn() *field.Error {
err := kmsArnRegexpValidator.ValidateKMSKeyARN(&r.Spec.EtcdEncryptionKMSArn)
if err != nil {
return field.Invalid(field.NewPath("spec.EtcdEncryptionKMSArn"), r.Spec.EtcdEncryptionKMSArn, err.Error())
}

return nil
}

// Default implements admission.Defaulter.
func (r *ROSAControlPlane) Default() {
SetObjectDefaults_ROSAControlPlane(r)
Expand Down
7 changes: 7 additions & 0 deletions controlplane/rosa/api/v1beta2/zz_generated.deepcopy.go

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

3 changes: 3 additions & 0 deletions controlplane/rosa/controllers/rosacontrolplane_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,9 @@ func (r *ROSAControlPlaneReconciler) reconcileNormal(ctx context.Context, rosaSc
DisableWorkloadMonitoring: ptr.To(true),
DefaultIngress: ocm.NewDefaultIngressSpec(), // n.b. this is a no-op when it's set to the default value
ComputeMachineType: rosaScope.ControlPlane.Spec.InstanceType,
Tags: rosaScope.ControlPlane.Spec.AdditionalTags,
EtcdEncryption: rosaScope.ControlPlane.Spec.EtcdEncryptionKMSArn != "",
EtcdEncryptionKMSArn: rosaScope.ControlPlane.Spec.EtcdEncryptionKMSArn,

SubnetIds: rosaScope.ControlPlane.Spec.Subnets,
AvailabilityZones: rosaScope.ControlPlane.Spec.AvailabilityZones,
Expand Down
2 changes: 0 additions & 2 deletions templates/cluster-template-rosa-machinepool.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ spec:
rosaClusterName: ${CLUSTER_NAME:0:15}
version: "${OPENSHIFT_VERSION}"
region: "${AWS_REGION}"
accountID: "${AWS_ACCOUNT_ID}"
creatorARN: "${AWS_CREATOR_ARN}"
network:
machineCIDR: "10.0.0.0/16"
rolesRef:
Expand Down
2 changes: 0 additions & 2 deletions templates/cluster-template-rosa.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ spec:
rosaClusterName: ${CLUSTER_NAME:0:15}
version: "${OPENSHIFT_VERSION}"
region: "${AWS_REGION}"
accountID: "${AWS_ACCOUNT_ID}"
creatorARN: "${AWS_CREATOR_ARN}"
network:
machineCIDR: "10.0.0.0/16"
rolesRef:
Expand Down

0 comments on commit be41c4f

Please sign in to comment.