Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions api/v1beta1/awscluster_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,40 +17,41 @@ limitations under the License.
package v1beta1

import (
infrav1 "sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta2"
infrav2 "sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta2"
utilconversion "sigs.k8s.io/cluster-api/util/conversion"
"sigs.k8s.io/controller-runtime/pkg/conversion"
)

// ConvertTo converts the v1beta1 AWSCluster receiver to a v1beta1 AWSCluster.
// ConvertTo converts the v1beta1 AWSCluster receiver to a v1beta2 AWSCluster.
func (src *AWSCluster) ConvertTo(dstRaw conversion.Hub) error {
dst := dstRaw.(*infrav1.AWSCluster)
dst := dstRaw.(*infrav2.AWSCluster)

if err := Convert_v1beta1_AWSCluster_To_v1beta2_AWSCluster(src, dst, nil); err != nil {
return err
}
// Manually restore data.
restored := &infrav1.AWSCluster{}
restored := &infrav2.AWSCluster{}
if ok, err := utilconversion.UnmarshalData(src, restored); err != nil || !ok {
return err
}

if restored.Spec.ControlPlaneLoadBalancer != nil {
if dst.Spec.ControlPlaneLoadBalancer == nil {
dst.Spec.ControlPlaneLoadBalancer = &infrav1.AWSLoadBalancerSpec{}
dst.Spec.ControlPlaneLoadBalancer = &infrav2.AWSLoadBalancerSpec{}
}
restoreControlPlaneLoadBalancer(restored.Spec.ControlPlaneLoadBalancer, dst.Spec.ControlPlaneLoadBalancer)
}
restoreControlPlaneLoadBalancerStatus(&restored.Status.Network.APIServerELB, &dst.Status.Network.APIServerELB)

dst.Spec.S3Bucket = restored.Spec.S3Bucket
dst.Spec.Partition = restored.Spec.Partition

return nil
}

// restoreControlPlaneLoadBalancerStatus manually restores the control plane loadbalancer status data.
// Assumes restored and dst are non-nil.
func restoreControlPlaneLoadBalancerStatus(restored, dst *infrav1.LoadBalancer) {
func restoreControlPlaneLoadBalancerStatus(restored, dst *infrav2.LoadBalancer) {
dst.ARN = restored.ARN
dst.LoadBalancerType = restored.LoadBalancerType
dst.ELBAttributes = restored.ELBAttributes
Expand All @@ -59,7 +60,7 @@ func restoreControlPlaneLoadBalancerStatus(restored, dst *infrav1.LoadBalancer)

// restoreControlPlaneLoadBalancer manually restores the control plane loadbalancer data.
// Assumes restored and dst are non-nil.
func restoreControlPlaneLoadBalancer(restored, dst *infrav1.AWSLoadBalancerSpec) {
func restoreControlPlaneLoadBalancer(restored, dst *infrav2.AWSLoadBalancerSpec) {
dst.Name = restored.Name
dst.HealthCheckProtocol = restored.HealthCheckProtocol
dst.LoadBalancerType = restored.LoadBalancerType
Expand All @@ -69,7 +70,7 @@ func restoreControlPlaneLoadBalancer(restored, dst *infrav1.AWSLoadBalancerSpec)

// ConvertFrom converts the v1beta1 AWSCluster receiver to a v1beta1 AWSCluster.
func (r *AWSCluster) ConvertFrom(srcRaw conversion.Hub) error {
src := srcRaw.(*infrav1.AWSCluster)
src := srcRaw.(*infrav2.AWSCluster)

if err := Convert_v1beta2_AWSCluster_To_v1beta1_AWSCluster(src, r, nil); err != nil {
return err
Expand All @@ -85,14 +86,14 @@ func (r *AWSCluster) ConvertFrom(srcRaw conversion.Hub) error {

// ConvertTo converts the v1beta1 AWSClusterList receiver to a v1beta2 AWSClusterList.
func (src *AWSClusterList) ConvertTo(dstRaw conversion.Hub) error {
dst := dstRaw.(*infrav1.AWSClusterList)
dst := dstRaw.(*infrav2.AWSClusterList)

return Convert_v1beta1_AWSClusterList_To_v1beta2_AWSClusterList(src, dst, nil)
}

// ConvertFrom converts the v1beta2 AWSClusterList receiver to a v1beta1 AWSClusterList.
func (r *AWSClusterList) ConvertFrom(srcRaw conversion.Hub) error {
src := srcRaw.(*infrav1.AWSClusterList)
src := srcRaw.(*infrav2.AWSClusterList)

return Convert_v1beta2_AWSClusterList_To_v1beta1_AWSClusterList(src, r, nil)
}
1 change: 1 addition & 0 deletions api/v1beta1/zz_generated.conversion.go

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

4 changes: 4 additions & 0 deletions api/v1beta2/awscluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ type AWSClusterSpec struct {
// The AWS Region the cluster lives in.
Region string `json:"region,omitempty"`

// Partition is the AWS security partition being used. Defaults to "aws"
// +optional
Partition string `json:"partition,omitempty"`

// SSHKeyName is the name of the ssh key to attach to the bastion host. Valid values are empty string (do not use SSH keys), a valid SSH key name, or omitted (use the default SSH key name)
// +optional
SSHKeyName *string `json:"sshKeyName,omitempty"`
Expand Down
2 changes: 2 additions & 0 deletions cmd/clusterawsadm/api/bootstrap/v1beta1/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ const (
DefaultStackName = "cluster-api-provider-aws-sigs-k8s-io"
// DefaultPartitionName is the default security partition for AWS ARNs.
DefaultPartitionName = "aws"
// PartitionNameUSGov is the default security partition for AWS ARNs.
PartitionNameUSGov = "aws-us-gov"
// DefaultKMSAliasPattern is the default KMS alias.
DefaultKMSAliasPattern = "cluster-api-provider-aws-*"
// DefaultS3BucketPrefix is the default S3 bucket prefix.
Expand Down
10 changes: 8 additions & 2 deletions cmd/clusterawsadm/cloudformation/bootstrap/fargate.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,18 @@ limitations under the License.
package bootstrap

import (
"strings"

bootstrapv1 "sigs.k8s.io/cluster-api-provider-aws/v2/cmd/clusterawsadm/api/bootstrap/v1beta1"
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/cloud/services/eks"
)

func fargateProfilePolicies(roleSpec *bootstrapv1.AWSIAMRoleSpec) []string {
policies := eks.FargateRolePolicies()
func (t Template) fargateProfilePolicies(roleSpec *bootstrapv1.AWSIAMRoleSpec) []string {
var policies []string
policies = eks.FargateRolePolicies()
if strings.Contains(t.Spec.Partition, bootstrapv1.PartitionNameUSGov) {
policies = eks.FargateRolePoliciesUSGov()
}
if roleSpec.ExtraPolicyAttachments != nil {
policies = append(policies, roleSpec.ExtraPolicyAttachments...)
}
Expand Down
14 changes: 12 additions & 2 deletions cmd/clusterawsadm/cloudformation/bootstrap/managed_nodegroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,20 @@ limitations under the License.

package bootstrap

import "sigs.k8s.io/cluster-api-provider-aws/v2/pkg/cloud/services/eks"
import (
"strings"

bootstrapv1 "sigs.k8s.io/cluster-api-provider-aws/v2/cmd/clusterawsadm/api/bootstrap/v1beta1"
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/cloud/services/eks"
)

func (t Template) eksMachinePoolPolicies() []string {
policies := eks.NodegroupRolePolicies()
var policies []string

policies = eks.NodegroupRolePolicies()
if strings.Contains(t.Spec.Partition, bootstrapv1.PartitionNameUSGov) {
policies = eks.NodegroupRolePoliciesUSGov()
}
if t.Spec.EKS.ManagedMachinePool.ExtraPolicyAttachments != nil {
policies = append(policies, t.Spec.EKS.ManagedMachinePool.ExtraPolicyAttachments...)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/clusterawsadm/cloudformation/bootstrap/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ func (t Template) RenderCloudFormation() *cloudformation.Template {
template.Resources[AWSIAMRoleEKSFargate] = &cfn_iam.Role{
RoleName: expinfrav1.DefaultEKSFargateRole,
AssumeRolePolicyDocument: AssumeRolePolicy(iamv1.PrincipalService, []string{eksiam.EKSFargateService}),
ManagedPolicyArns: fargateProfilePolicies(t.Spec.EKS.Fargate),
ManagedPolicyArns: t.fargateProfilePolicies(t.Spec.EKS.Fargate),
Tags: converters.MapToCloudFormationTags(t.Spec.EKS.Fargate.Tags),
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1936,6 +1936,10 @@ spec:
prefixing.
type: string
type: object
partition:
description: Partition is the AWS security partition being used. Defaults
to "aws"
type: string
region:
description: The AWS Region the cluster lives in.
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1241,6 +1241,10 @@ spec:
type: object
type: object
type: object
partition:
description: Partition is the AWS security partition being used. Defaults
to "aws"
type: string
region:
description: The AWS Region the cluster lives in.
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,10 @@ spec:
type: object
type: object
type: object
partition:
description: Partition is the AWS security partition being
used. Defaults to "aws"
type: string
region:
description: The AWS Region the cluster lives in.
type: string
Expand Down
10 changes: 8 additions & 2 deletions controlplane/eks/api/v1beta1/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,14 @@ func (r *AWSManagedControlPlane) ConvertTo(dstRaw conversion.Hub) error {
if err := Convert_v1beta1_AWSManagedControlPlane_To_v1beta2_AWSManagedControlPlane(r, dst, nil); err != nil {
return err
}

// Manually restore data.
restored := &ekscontrolplanev1.AWSManagedControlPlane{}
if ok, err := utilconversion.UnmarshalData(r, restored); err != nil || !ok {
return err
}
dst.Spec.VpcCni.Disable = r.Spec.DisableVPCCNI
dst.Spec.Partition = restored.Spec.Partition

return nil
}
Expand All @@ -50,7 +51,7 @@ func (r *AWSManagedControlPlane) ConvertFrom(srcRaw conversion.Hub) error {
if err := Convert_v1beta2_AWSManagedControlPlane_To_v1beta1_AWSManagedControlPlane(src, r, nil); err != nil {
return err
}

r.Spec.DisableVPCCNI = src.Spec.VpcCni.Disable
if err := utilconversion.MarshalData(src, r); err != nil {
return err
Expand Down Expand Up @@ -110,3 +111,8 @@ func Convert_v1beta1_AWSManagedControlPlaneSpec_To_v1beta2_AWSManagedControlPlan
func Convert_v1beta2_VpcCni_To_v1beta1_VpcCni(in *ekscontrolplanev1.VpcCni, out *VpcCni, s apiconversion.Scope) error {
return autoConvert_v1beta2_VpcCni_To_v1beta1_VpcCni(in, out, s)
}

// Convert_v1beta2_AWSManagedControlPlaneSpec_To_v1beta1_AWSManagedControlPlaneSpec is a generated conversion function
func Convert_v1beta2_AWSManagedControlPlaneSpec_To_v1beta1_AWSManagedControlPlaneSpec(in *ekscontrolplanev1.AWSManagedControlPlaneSpec, out *AWSManagedControlPlaneSpec, scope apiconversion.Scope) error {
return autoConvert_v1beta2_AWSManagedControlPlaneSpec_To_v1beta1_AWSManagedControlPlaneSpec(in, out, scope)
}
10 changes: 5 additions & 5 deletions controlplane/eks/api/v1beta1/conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ package v1beta1

import (
"testing"

. "github.com/onsi/gomega"

fuzz "github.com/google/gofuzz"
"k8s.io/apimachinery/pkg/api/apitesting/fuzzer"
"k8s.io/apimachinery/pkg/runtime"
Expand All @@ -47,9 +47,9 @@ func TestFuzzyConversion(t *testing.T) {
g.Expect(v1beta2.AddToScheme(scheme)).To(Succeed())

t.Run("for AWSManagedControlPlane", utilconversion.FuzzTestFunc(utilconversion.FuzzTestFuncInput{
Scheme: scheme,
Hub: &v1beta2.AWSManagedControlPlane{},
Spoke: &AWSManagedControlPlane{},
Scheme: scheme,
Hub: &v1beta2.AWSManagedControlPlane{},
Spoke: &AWSManagedControlPlane{},
FuzzerFuncs: []fuzzer.FuzzerFuncs{fuzzFuncs},
}))
}
16 changes: 6 additions & 10 deletions controlplane/eks/api/v1beta1/zz_generated.conversion.go

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

4 changes: 4 additions & 0 deletions controlplane/eks/api/v1beta2/awsmanagedcontrolplane_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ type AWSManagedControlPlaneSpec struct { //nolint: maligned
// The AWS Region the cluster lives in.
Region string `json:"region,omitempty"`

// Partition is the AWS security partition being used. Defaults to "aws"
// +optional
Partition string `json:"partition,omitempty"`

// SSHKeyName is the name of the ssh key to attach to the bastion host. Valid values are empty string (do not use SSH keys), a valid SSH key name, or omitted (use the default SSH key name)
// +optional
SSHKeyName *string `json:"sshKeyName,omitempty"`
Expand Down
3 changes: 3 additions & 0 deletions controlplane/eks/api/v1beta2/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@ func (*AWSManagedControlPlane) Hub() {}

// Hub marks AWSManagedControlPlaneList as a conversion hub.
func (*AWSManagedControlPlaneList) Hub() {}

// Hub marks AWSManagedControlPlaneSpec as a conversion hub.
func (*AWSManagedControlPlaneSpec) Hub() {}
9 changes: 9 additions & 0 deletions pkg/cloud/scope/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/cloud"
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/cloud/throttle"
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/logger"
"sigs.k8s.io/cluster-api-provider-aws/v2/util/system"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
"sigs.k8s.io/cluster-api/util/conditions"
"sigs.k8s.io/cluster-api/util/patch"
Expand Down Expand Up @@ -351,3 +352,11 @@ func (s *ClusterScope) ImageLookupOrg() string {
func (s *ClusterScope) ImageLookupBaseOS() string {
return s.AWSCluster.Spec.ImageLookupBaseOS
}

// Partition returns the cluster partition.
func (s *ClusterScope) Partition() string {
if s.AWSCluster.Spec.Partition == "" {
s.AWSCluster.Spec.Partition = system.GetPartitionFromRegion(s.Region())
}
return s.AWSCluster.Spec.Partition
}
9 changes: 9 additions & 0 deletions pkg/cloud/scope/fargate.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/cloud"
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/cloud/throttle"
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/logger"
"sigs.k8s.io/cluster-api-provider-aws/v2/util/system"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
"sigs.k8s.io/cluster-api/util/conditions"
"sigs.k8s.io/cluster-api/util/patch"
Expand Down Expand Up @@ -157,6 +158,14 @@ func (s *FargateProfileScope) SubnetIDs() []string {
return s.FargateProfile.Spec.SubnetIDs
}

// Partition returns the machine pool subnet IDs.
func (s *FargateProfileScope) Partition() string {
if s.ControlPlane.Spec.Partition == "" {
s.ControlPlane.Spec.Partition = system.GetPartitionFromRegion(s.ControlPlane.Spec.Region)
}
return s.ControlPlane.Spec.Partition
}

// IAMReadyFalse marks the ready condition false using warning if error isn't
// empty.
func (s *FargateProfileScope) IAMReadyFalse(reason string, err string) error {
Expand Down
9 changes: 9 additions & 0 deletions pkg/cloud/scope/managedcontrolplane.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/cloud"
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/cloud/throttle"
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/logger"
"sigs.k8s.io/cluster-api-provider-aws/v2/util/system"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
"sigs.k8s.io/cluster-api/controllers/remote"
"sigs.k8s.io/cluster-api/util/patch"
Expand Down Expand Up @@ -401,3 +402,11 @@ func (s *ManagedControlPlaneScope) ServiceCidrs() *clusterv1.NetworkRanges {
func (s *ManagedControlPlaneScope) ControlPlaneLoadBalancer() *infrav1.AWSLoadBalancerSpec {
return nil
}

// Partition returns the cluster partition.
func (s *ManagedControlPlaneScope) Partition() string {
if s.ControlPlane.Spec.Partition == "" {
s.ControlPlane.Spec.Partition = system.GetPartitionFromRegion(s.Region())
}
return s.ControlPlane.Spec.Partition
}
Loading