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

     1  /*
     2  Copyright 2020 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 v1alpha1
    18  
    19  import (
    20  	runtime "k8s.io/apimachinery/pkg/runtime"
    21  	utilpointer "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  )
    37  
    38  func addDefaultingFuncs(scheme *runtime.Scheme) error {
    39  	return RegisterDefaults(scheme)
    40  }
    41  
    42  // SetDefaults_BootstrapUser is used by defaulter-gen.
    43  func SetDefaults_BootstrapUser(obj *BootstrapUser) { //nolint:golint,stylecheck
    44  	if obj != nil && obj.UserName == "" {
    45  		obj.UserName = DefaultBootstrapUserName
    46  	}
    47  }
    48  
    49  // SetDefaults_AWSIAMConfigurationSpec is used by defaulter-gen.
    50  func SetDefaults_AWSIAMConfigurationSpec(obj *AWSIAMConfigurationSpec) { //nolint:golint,stylecheck
    51  	if obj.NameSuffix == nil {
    52  		obj.NameSuffix = utilpointer.StringPtr(iamv1.DefaultNameSuffix)
    53  	}
    54  	if obj.Partition == "" {
    55  		obj.Partition = DefaultPartitionName
    56  	}
    57  	if obj.StackName == "" {
    58  		obj.StackName = DefaultStackName
    59  	}
    60  	if obj.EKS == nil {
    61  		obj.EKS = &EKSConfig{
    62  			Disable:              false,
    63  			AllowIAMRoleCreation: false,
    64  			DefaultControlPlaneRole: AWSIAMRoleSpec{
    65  				Disable: false,
    66  			},
    67  		}
    68  	} else if !obj.EKS.Disable {
    69  		obj.Nodes.EC2ContainerRegistryReadOnly = true
    70  	}
    71  	if obj.EventBridge == nil {
    72  		obj.EventBridge = &EventBridgeConfig{
    73  			Enable: false,
    74  		}
    75  	}
    76  	if obj.EKS.ManagedMachinePool == nil {
    77  		obj.EKS.ManagedMachinePool = &AWSIAMRoleSpec{
    78  			Disable: true,
    79  		}
    80  	}
    81  	if obj.EKS.Fargate == nil {
    82  		obj.EKS.Fargate = &AWSIAMRoleSpec{
    83  			Disable: true,
    84  		}
    85  	}
    86  	if len(obj.SecureSecretsBackends) == 0 {
    87  		obj.SecureSecretsBackends = []infrav1.SecretBackend{
    88  			infrav1.SecretBackendSecretsManager,
    89  		}
    90  	}
    91  	if len(obj.EKS.KMSAliasPrefix) == 0 {
    92  		obj.EKS.KMSAliasPrefix = DefaultKMSAliasPattern
    93  	}
    94  }
    95  
    96  // SetDefaults_AWSIAMConfiguration is used by defaulter-gen.
    97  func SetDefaults_AWSIAMConfiguration(obj *AWSIAMConfiguration) { //nolint:golint,stylecheck
    98  	obj.APIVersion = SchemeGroupVersion.String()
    99  	obj.Kind = "AWSIAMConfiguration"
   100  	if obj.Spec.NameSuffix == nil {
   101  		obj.Spec.NameSuffix = utilpointer.StringPtr(iamv1.DefaultNameSuffix)
   102  	}
   103  	if obj.Spec.StackName == "" {
   104  		obj.Spec.StackName = DefaultStackName
   105  	}
   106  }