From d6aca6a120c30d30ecd8b4fcbf097b54f6d686ce Mon Sep 17 00:00:00 2001 From: Artiom Diomin Date: Tue, 7 Oct 2025 12:29:54 +0300 Subject: [PATCH] Delete everything related to Amazon Linux 2 Signed-off-by: Artiom Diomin --- pkg/cloudprovider/provider/aws/provider.go | 33 +++--------- sdk/providerconfig/types.go | 16 +++--- sdk/userdata/amzn2/config.go | 59 ---------------------- sdk/userdata/default.go | 3 -- test/e2e/provisioning/helper.go | 1 - 5 files changed, 14 insertions(+), 98 deletions(-) delete mode 100644 sdk/userdata/amzn2/config.go diff --git a/pkg/cloudprovider/provider/aws/provider.go b/pkg/cloudprovider/provider/aws/provider.go index 8c48823d6..b3829c1a9 100644 --- a/pkg/cloudprovider/provider/aws/provider.go +++ b/pkg/cloudprovider/provider/aws/provider.go @@ -66,11 +66,10 @@ const ( awsMetadataHTTPPutResponseHopLimit = 3 ) -var ( - metricInstancesForMachines = prometheus.NewGaugeVec(prometheus.GaugeOpts{ - Name: "machine_controller_aws_instances_for_machine", - Help: "The number of instances at aws for a given machine"}, []string{"machine"}) -) +var metricInstancesForMachines = prometheus.NewGaugeVec(prometheus.GaugeOpts{ + Name: "machine_controller_aws_instances_for_machine", + Help: "The number of instances at aws for a given machine", +}, []string{"machine"}) func init() { metrics.Registry.MustRegister(metricInstancesForMachines) @@ -115,18 +114,6 @@ var ( owner: "792107900819", }, }, - providerconfig.OperatingSystemAmazonLinux2: { - awstypes.CPUArchitectureX86_64: { - description: "Amazon Linux 2 AMI * x86_64 HVM gp2", - // The AWS marketplace ID from Amazon - owner: "137112412989", - }, - awstypes.CPUArchitectureARM64: { - description: "Amazon Linux 2 LTS Arm64 AMI * arm64 HVM gp2", - // The AWS marketplace ID from Amazon - owner: "137112412989", - }, - }, providerconfig.OperatingSystemUbuntu: { awstypes.CPUArchitectureX86_64: { // Be as precise as possible - otherwise we might get a nightly dev build @@ -290,7 +277,6 @@ func getCPUArchitecture(ctx context.Context, client *ec2.Client, instanceType ec instanceTypes, err := client.DescribeInstanceTypes(ctx, &ec2.DescribeInstanceTypesInput{ InstanceTypes: []ec2types.InstanceType{instanceType}, }) - if err != nil { return "", err } @@ -328,8 +314,6 @@ func getDefaultRootDevicePath(os providerconfig.OperatingSystem) (string, error) return rootDevicePathSDA, nil case providerconfig.OperatingSystemFlatcar: return rootDevicePathXVDA, nil - case providerconfig.OperatingSystemAmazonLinux2: - return rootDevicePathXVDA, nil } return "", fmt.Errorf("no default root path found for %s operating system", os) @@ -474,7 +458,6 @@ func getAwsConfig(ctx context.Context, id, secret, token, region, assumeRoleARN, awsconfig.WithCredentialsProvider(awscredentials.NewStaticCredentialsProvider(id, secret, token)), awsconfig.WithRetryMaxAttempts(maxRetries), ) - if err != nil { return aws.Config{}, err } @@ -624,7 +607,6 @@ func getVpc(ctx context.Context, client *ec2.Client, id string) (*ec2types.Vpc, {Name: aws.String("vpc-id"), Values: []string{id}}, }, }) - if err != nil { return nil, awsErrorToTerminalError(err, "failed to list vpc's") } @@ -641,7 +623,6 @@ func areVpcDNSHostnamesEnabled(ctx context.Context, client *ec2.Client, id strin VpcId: &id, Attribute: ec2types.VpcAttributeNameEnableDnsHostnames, }) - if err != nil { return false, awsErrorToTerminalError(err, "failed to describe vpc attributes") } @@ -676,7 +657,6 @@ func (p *provider) Create(ctx context.Context, log *zap.SugaredLogger, machine * if amiID == "" { // read the instance type to know which cpu architecture is needed in the AMI cpuArchitecture, err := getCPUArchitecture(ctx, ec2Client, config.InstanceType) - if err != nil { return nil, cloudprovidererrors.TerminalError{ Reason: common.InvalidConfigurationMachineError, @@ -819,7 +799,6 @@ func (p *provider) Cleanup(ctx context.Context, log *zap.SugaredLogger, machine // (*Config, *providerconfig.Config, *awstypes.RawConfig, error) config, _, _, err := p.getConfig(machine.Spec.ProviderSpec) - if err != nil { return false, cloudprovidererrors.TerminalError{ Reason: common.InvalidConfigurationMachineError, @@ -837,7 +816,6 @@ func (p *provider) Cleanup(ctx context.Context, log *zap.SugaredLogger, machine cOut, err := ec2Client.CancelSpotInstanceRequests(ctx, &ec2.CancelSpotInstanceRequestsInput{ SpotInstanceRequestIds: []string{*ec2instance.instance.SpotInstanceRequestId}, }) - if err != nil { return false, awsErrorToTerminalError(err, "failed to cancel spot instance request") } @@ -946,7 +924,8 @@ func (p *provider) MigrateUID(ctx context.Context, _ *zap.SugaredLogger, machine _, err = ec2Client.CreateTags(ctx, &ec2.CreateTagsInput{ Resources: []string{machineInstance.ID()}, - Tags: []ec2types.Tag{{Key: aws.String(machineUIDTag), Value: aws.String(string(newUID))}}}) + Tags: []ec2types.Tag{{Key: aws.String(machineUIDTag), Value: aws.String(string(newUID))}}, + }) if err != nil { return fmt.Errorf("failed to update instance with new machineUIDTag: %w", err) } diff --git a/sdk/providerconfig/types.go b/sdk/providerconfig/types.go index b986a8a8b..a7cfd951f 100644 --- a/sdk/providerconfig/types.go +++ b/sdk/providerconfig/types.go @@ -35,11 +35,10 @@ import ( type OperatingSystem string const ( - OperatingSystemUbuntu OperatingSystem = "ubuntu" - OperatingSystemAmazonLinux2 OperatingSystem = "amzn2" - OperatingSystemRHEL OperatingSystem = "rhel" - OperatingSystemFlatcar OperatingSystem = "flatcar" - OperatingSystemRockyLinux OperatingSystem = "rockylinux" + OperatingSystemUbuntu OperatingSystem = "ubuntu" + OperatingSystemRHEL OperatingSystem = "rhel" + OperatingSystemFlatcar OperatingSystem = "flatcar" + OperatingSystemRockyLinux OperatingSystem = "rockylinux" ) func (os OperatingSystem) Validate() error { @@ -84,7 +83,6 @@ var ( // AllOperatingSystems is a slice containing all supported operating system identifiers. AllOperatingSystems = []OperatingSystem{ OperatingSystemUbuntu, - OperatingSystemAmazonLinux2, OperatingSystemRHEL, OperatingSystemFlatcar, OperatingSystemRockyLinux, @@ -177,8 +175,10 @@ type GlobalObjectKeySelector struct { Key string `json:"key,omitempty"` } -type GlobalSecretKeySelector GlobalObjectKeySelector -type GlobalConfigMapKeySelector GlobalObjectKeySelector +type ( + GlobalSecretKeySelector GlobalObjectKeySelector + GlobalConfigMapKeySelector GlobalObjectKeySelector +) type ConfigVarString struct { Value string `json:"value,omitempty"` diff --git a/sdk/userdata/amzn2/config.go b/sdk/userdata/amzn2/config.go deleted file mode 100644 index b836ce70a..000000000 --- a/sdk/userdata/amzn2/config.go +++ /dev/null @@ -1,59 +0,0 @@ -/* -Copyright 2021 The Machine Controller Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package amzn2 - -import ( - "encoding/json" - - "k8s.io/apimachinery/pkg/runtime" -) - -// Config contains specific configuration for Amazon Linux 2. -type Config struct { - DistUpgradeOnBoot bool `json:"distUpgradeOnBoot"` -} - -func DefaultConfig(operatingSystemSpec runtime.RawExtension) runtime.RawExtension { - if operatingSystemSpec.Raw == nil { - operatingSystemSpec.Raw, _ = json.Marshal(Config{}) - } - - return operatingSystemSpec -} - -// LoadConfig retrieves the Amazon Linux 2 configuration from raw data. -func LoadConfig(r runtime.RawExtension) (*Config, error) { - r = DefaultConfig(r) - cfg := Config{} - - if err := json.Unmarshal(r.Raw, &cfg); err != nil { - return nil, err - } - return &cfg, nil -} - -// Spec return the configuration as raw data. -func (cfg *Config) Spec() (*runtime.RawExtension, error) { - ext := &runtime.RawExtension{} - b, err := json.Marshal(cfg) - if err != nil { - return nil, err - } - - ext.Raw = b - return ext, nil -} diff --git a/sdk/userdata/default.go b/sdk/userdata/default.go index 6fa5e9b9b..3533c3b23 100644 --- a/sdk/userdata/default.go +++ b/sdk/userdata/default.go @@ -20,7 +20,6 @@ import ( "errors" "k8c.io/machine-controller/sdk/providerconfig" - "k8c.io/machine-controller/sdk/userdata/amzn2" "k8c.io/machine-controller/sdk/userdata/flatcar" "k8c.io/machine-controller/sdk/userdata/rhel" "k8c.io/machine-controller/sdk/userdata/rockylinux" @@ -31,8 +30,6 @@ import ( func DefaultOperatingSystemSpec(os providerconfig.OperatingSystem, operatingSystemSpec runtime.RawExtension) (runtime.RawExtension, error) { switch os { - case providerconfig.OperatingSystemAmazonLinux2: - return amzn2.DefaultConfig(operatingSystemSpec), nil case providerconfig.OperatingSystemFlatcar: return flatcar.DefaultConfig(operatingSystemSpec), nil case providerconfig.OperatingSystemRHEL: diff --git a/test/e2e/provisioning/helper.go b/test/e2e/provisioning/helper.go index d22e89473..9e0609e94 100644 --- a/test/e2e/provisioning/helper.go +++ b/test/e2e/provisioning/helper.go @@ -42,7 +42,6 @@ var ( operatingSystems = []providerconfigtypes.OperatingSystem{ providerconfigtypes.OperatingSystemUbuntu, - providerconfigtypes.OperatingSystemAmazonLinux2, providerconfigtypes.OperatingSystemRHEL, providerconfigtypes.OperatingSystemFlatcar, providerconfigtypes.OperatingSystemRockyLinux,