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 committed Feb 22, 2024
1 parent 8b4231d commit c3e886c
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ spec:
type: object
spec:
properties:
additionalTags:
additionalProperties:
type: string
description: User-defined tags for AWS resources
type: object
availabilityZones:
description: AWS AvailabilityZones of the worker nodes should match
the AvailabilityZones of the Subnets.
Expand Down Expand Up @@ -78,6 +83,11 @@ spec:
type: string
type: object
x-kubernetes-map-type: atomic
etcdEncryptionKMSArn:
description: The etcd encryption kms key ARN is the key used to encrypt
etcd. It is only allowed for hosted cp and it needs to be pre-created
in AWS KMS with tag 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 @@ -79,6 +79,15 @@ type RosaControlPlaneSpec struct { //nolint: maligned
// IdentityRef is a reference to an identity to be used when reconciling the managed control plane.
// If no identity is specified, the default identity for this controller will be used.
IdentityRef *infrav1.AWSIdentityReference `json:"identityRef,omitempty"`

// User-defined tags for AWS resources
// +optional
AdditionalTags infrav1.Tags `json:"additionalTags,omitempty"`

// The etcd encryption kms key ARN is the key used to encrypt etcd.
// It is only allowed for hosted cp and it needs to be pre-created in AWS KMS with tag red-hat:true.
// +optional
EtcdEncryptionKMSArn string `json:"etcdEncryptionKMSArn,omitempty"`
}

// AWSRolesRef contains references to various AWS IAM roles required for operators to make calls against the AWS API.
Expand Down
23 changes: 23 additions & 0 deletions controlplane/rosa/api/v1beta2/rosacontrolplane_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package v1beta2

import (
"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 @@ -31,6 +32,12 @@ func (r *ROSAControlPlane) ValidateCreate() (warnings admission.Warnings, err er
allErrs = append(allErrs, err)
}

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

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

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

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

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

if len(allErrs) == 0 {
return nil, nil
}
Expand All @@ -75,6 +88,16 @@ func (r *ROSAControlPlane) validateVersion() *field.Error {
return nil
}

func (r *ROSAControlPlane) validateKMSKeyARN() *field.Error {
// validate Etcd Encryption KMS Arn
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.

20 changes: 19 additions & 1 deletion controlplane/rosa/controllers/rosacontrolplane_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,6 @@ func (r *ROSAControlPlaneReconciler) reconcileNormal(ctx context.Context, rosaSc
ID(*rosaScope.ControlPlane.Spec.Region),
).
FIPS(false).
EtcdEncryption(false).
DisableUserWorkloadMonitoring(true).
Version(
cmv1.NewVersion().
Expand All @@ -279,6 +278,14 @@ func (r *ROSAControlPlaneReconciler) reconcileNormal(ctx context.Context, rosaSc
ExpirationTimestamp(time.Now().Add(1 * time.Hour)).
Hypershift(cmv1.NewHypershift().Enabled(true))

etcdEncryption := false
// If EtcdEncryptionKMSArn is set, etcdEncryption is true.
if rosaScope.ControlPlane.Spec.EtcdEncryptionKMSArn != "" {
etcdEncryption = true
}

clusterBuilder = clusterBuilder.EtcdEncryption(etcdEncryption)

networkBuilder := cmv1.NewNetwork()
networkBuilder = networkBuilder.Type("OVNKubernetes")
networkBuilder = networkBuilder.MachineCIDR(*rosaScope.ControlPlane.Spec.MachineCIDR)
Expand Down Expand Up @@ -353,6 +360,17 @@ func (r *ROSAControlPlaneReconciler) reconcileNormal(ctx context.Context, rosaSc
BillingAccountID(*rosaScope.Identity.Account).
SubnetIDs(rosaScope.ControlPlane.Spec.Subnets...).
STS(stsBuilder)

// specify additional tags
if len(rosaScope.ControlPlane.Spec.AdditionalTags) > 0 {
awsBuilder = awsBuilder.Tags(rosaScope.ControlPlane.Spec.AdditionalTags)
}

// etcd encryption kms key arn
if rosaScope.ControlPlane.Spec.EtcdEncryptionKMSArn != "" {
awsBuilder = awsBuilder.EtcdEncryption(cmv1.NewAwsEtcdEncryption().KMSKeyARN(rosaScope.ControlPlane.Spec.EtcdEncryptionKMSArn))
}

clusterBuilder = clusterBuilder.AWS(awsBuilder)

clusterNodesBuilder := cmv1.NewClusterNodes()
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ require (
github.com/google/gofuzz v1.2.0
github.com/onsi/ginkgo/v2 v2.13.1
github.com/onsi/gomega v1.30.0
github.com/openshift-online/ocm-sdk-go v0.1.388
github.com/openshift-online/ocm-common v0.0.0-20240129111424-ff8c6c11d909
github.com/openshift-online/ocm-sdk-go v0.1.391
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.17.0
github.com/sergi/go-diff v1.3.1
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -466,8 +466,10 @@ github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
github.com/opencontainers/image-spec v1.1.0-rc2.0.20221005185240-3a7f492d3f1b h1:YWuSjZCQAPM8UUBLkYUk1e+rZcvWHJmFb6i6rM44Xs8=
github.com/opencontainers/image-spec v1.1.0-rc2.0.20221005185240-3a7f492d3f1b/go.mod h1:3OVijpioIKYWTqjiG0zfF6wvoJ4fAXGbjdZuI2NgsRQ=
github.com/openshift-online/ocm-sdk-go v0.1.388 h1:c8yPCUQwJm3QhcVmnyMPFpeDtxPBaPeYh5hLv1vg9YQ=
github.com/openshift-online/ocm-sdk-go v0.1.388/go.mod h1:/+VFIw1iW2H0jEkFH4GnbL/liWareyzsL0w7mDIudB4=
github.com/openshift-online/ocm-common v0.0.0-20240129111424-ff8c6c11d909 h1:WV67GNazQuGDaLX3kBbz0859NYPOQCsDCY5XUScF85M=
github.com/openshift-online/ocm-common v0.0.0-20240129111424-ff8c6c11d909/go.mod h1:7FaAb07S63RF4sFMLSLtQaJLvPdaRnhAT4dBLD8/5kM=
github.com/openshift-online/ocm-sdk-go v0.1.391 h1:BCC/sM1gVooxCL76MiPux2kng8MUbwM1IQr62hMPXeU=
github.com/openshift-online/ocm-sdk-go v0.1.391/go.mod h1:/+VFIw1iW2H0jEkFH4GnbL/liWareyzsL0w7mDIudB4=
github.com/pelletier/go-toml v1.9.4/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=
github.com/pelletier/go-toml v1.9.5 h1:4yBQzkHv+7BHq2PQUZF3Mx0IYxG7LsP222s7Agd3ve8=
github.com/pelletier/go-toml v1.9.5/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=
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}"
machineCIDR: "10.0.0.0/16"
rolesRef:
ingressARN: "arn:aws:iam::${AWS_ACCOUNT_ID}:role/${OPERATOR_ROLES_PREFIX}-openshift-ingress-operator-cloud-credentials"
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}"
machineCIDR: "10.0.0.0/16"
rolesRef:
ingressARN: "arn:aws:iam::${AWS_ACCOUNT_ID}:role/${OPERATOR_ROLES_PREFIX}-openshift-ingress-operator-cloud-credentials"
Expand Down

0 comments on commit c3e886c

Please sign in to comment.