sigs.k8s.io/cluster-api-provider-aws@v1.5.5/cmd/clusterawsadm/api/bootstrap/v1beta1/defaults.go (about)

     1  /*
     2  Copyright 2021 The Kubernetes Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8  	http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package v1beta1
    18  
    19  import (
    20  	runtime "k8s.io/apimachinery/pkg/runtime"
    21  	"k8s.io/utils/pointer"
    22  
    23  	infrav1 "sigs.k8s.io/cluster-api-provider-aws/api/v1beta1"
    24  	iamv1 "sigs.k8s.io/cluster-api-provider-aws/iam/api/v1beta1"
    25  )
    26  
    27  const (
    28  	// DefaultBootstrapUserName is the default bootstrap user name.
    29  	DefaultBootstrapUserName = "bootstrapper.cluster-api-provider-aws.sigs.k8s.io"
    30  	// DefaultStackName is the default CloudFormation stack name.
    31  	DefaultStackName = "cluster-api-provider-aws-sigs-k8s-io"
    32  	// DefaultPartitionName is the default security partition for AWS ARNs.
    33  	DefaultPartitionName = "aws"
    34  	// DefaultKMSAliasPattern is the default KMS alias.
    35  	DefaultKMSAliasPattern = "cluster-api-provider-aws-*"
    36  	// DefaultS3BucketPrefix is the default S3 bucket prefix.
    37  	DefaultS3BucketPrefix = "cluster-api-provider-aws-"
    38  )
    39  
    40  func addDefaultingFuncs(scheme *runtime.Scheme) error {
    41  	return RegisterDefaults(scheme)
    42  }
    43  
    44  // SetDefaults_BootstrapUser is used by defaulter-gen.
    45  func SetDefaults_BootstrapUser(obj *BootstrapUser) { //nolint:golint,stylecheck
    46  	if obj != nil && obj.UserName == "" {
    47  		obj.UserName = DefaultBootstrapUserName
    48  	}
    49  }
    50  
    51  // SetDefaults_AWSIAMConfigurationSpec is used by defaulter-gen.
    52  func SetDefaults_AWSIAMConfigurationSpec(obj *AWSIAMConfigurationSpec) { //nolint:golint,stylecheck
    53  	if obj.NameSuffix == nil {
    54  		obj.NameSuffix = pointer.StringPtr(iamv1.DefaultNameSuffix)
    55  	}
    56  	if obj.Partition == "" {
    57  		obj.Partition = DefaultPartitionName
    58  	}
    59  	if obj.StackName == "" {
    60  		obj.StackName = DefaultStackName
    61  	}
    62  	if obj.EKS == nil {
    63  		obj.EKS = &EKSConfig{
    64  			Disable:              false,
    65  			AllowIAMRoleCreation: false,
    66  			DefaultControlPlaneRole: AWSIAMRoleSpec{
    67  				Disable: false,
    68  			},
    69  		}
    70  	} else if !obj.EKS.Disable {
    71  		obj.Nodes.EC2ContainerRegistryReadOnly = true
    72  	}
    73  	if obj.EventBridge == nil {
    74  		obj.EventBridge = &EventBridgeConfig{
    75  			Enable: false,
    76  		}
    77  	}
    78  	if obj.EKS.ManagedMachinePool == nil {
    79  		obj.EKS.ManagedMachinePool = &AWSIAMRoleSpec{
    80  			Disable: true,
    81  		}
    82  	}
    83  	if obj.EKS.Fargate == nil {
    84  		obj.EKS.Fargate = &AWSIAMRoleSpec{
    85  			Disable: true,
    86  		}
    87  	}
    88  	if len(obj.SecureSecretsBackends) == 0 {
    89  		obj.SecureSecretsBackends = []infrav1.SecretBackend{
    90  			infrav1.SecretBackendSecretsManager,
    91  		}
    92  	}
    93  	if len(obj.EKS.KMSAliasPrefix) == 0 {
    94  		obj.EKS.KMSAliasPrefix = DefaultKMSAliasPattern
    95  	}
    96  
    97  	if obj.S3Buckets.NamePrefix == "" {
    98  		obj.S3Buckets.NamePrefix = DefaultS3BucketPrefix
    99  	}
   100  }
   101  
   102  // SetDefaults_AWSIAMConfiguration is used by defaulter-gen.
   103  func SetDefaults_AWSIAMConfiguration(obj *AWSIAMConfiguration) { //nolint:golint,stylecheck
   104  	obj.APIVersion = SchemeGroupVersion.String()
   105  	obj.Kind = "AWSIAMConfiguration"
   106  	if obj.Spec.NameSuffix == nil {
   107  		obj.Spec.NameSuffix = pointer.StringPtr(iamv1.DefaultNameSuffix)
   108  	}
   109  	if obj.Spec.StackName == "" {
   110  		obj.Spec.StackName = DefaultStackName
   111  	}
   112  }