Skip to content

Commit

Permalink
Migrate to openshift/api
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-demicev committed Oct 29, 2021
1 parent 1c1622f commit acf692a
Show file tree
Hide file tree
Showing 16 changed files with 262 additions and 208 deletions.
4 changes: 2 additions & 2 deletions cmd/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"time"

configv1 "github.com/openshift/api/config/v1"
mapiv1beta1 "github.com/openshift/machine-api-operator/pkg/apis/machine/v1beta1"
machinev1 "github.com/openshift/api/machine/v1beta1"
"github.com/openshift/machine-api-operator/pkg/controller/machine"
"github.com/openshift/machine-api-operator/pkg/metrics"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -132,7 +132,7 @@ func main() {
}

// Setup Scheme for all resources
if err := mapiv1beta1.AddToScheme(mgr.GetScheme()); err != nil {
if err := machinev1.AddToScheme(mgr.GetScheme()); err != nil {
klog.Fatalf("Error setting up scheme: %v", err)
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/actuators/machine/actuator.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"context"
"fmt"

machinev1 "github.com/openshift/machine-api-operator/pkg/apis/machine/v1beta1"
machinev1 "github.com/openshift/api/machine/v1beta1"
corev1 "k8s.io/api/core/v1"
"k8s.io/client-go/tools/record"
"k8s.io/klog/v2"
Expand Down
2 changes: 1 addition & 1 deletion pkg/actuators/machine/actuator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/golang/mock/gomock"
. "github.com/onsi/gomega"
configv1 "github.com/openshift/api/config/v1"
machinev1 "github.com/openshift/machine-api-operator/pkg/apis/machine/v1beta1"
machinev1 "github.com/openshift/api/machine/v1beta1"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
Expand Down
45 changes: 21 additions & 24 deletions pkg/actuators/machine/instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,16 @@ import (
"strings"
"time"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/service/ec2"
configv1 "github.com/openshift/api/config/v1"
machinev1 "github.com/openshift/machine-api-operator/pkg/apis/machine/v1beta1"
machinev1 "github.com/openshift/api/machine/v1beta1"
mapierrors "github.com/openshift/machine-api-operator/pkg/controller/machine"
"github.com/openshift/machine-api-operator/pkg/metrics"
"k8s.io/klog/v2"
awsproviderv1 "sigs.k8s.io/cluster-api-provider-aws/pkg/apis/awsprovider/v1beta1"
runtimeclient "sigs.k8s.io/controller-runtime/pkg/client"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/ec2"

awsclient "sigs.k8s.io/cluster-api-provider-aws/pkg/client"
runtimeclient "sigs.k8s.io/controller-runtime/pkg/client"
)

// Scan machine tags, and return a deduped tags list. The first found value gets precedence.
Expand Down Expand Up @@ -56,7 +53,7 @@ func removeStoppedMachine(machine *machinev1.Machine, client awsclient.Client) e
return err
}

func buildEC2Filters(inputFilters []awsproviderv1.Filter) []*ec2.Filter {
func buildEC2Filters(inputFilters []machinev1.Filter) []*ec2.Filter {
filters := make([]*ec2.Filter, len(inputFilters))
for i, f := range inputFilters {
values := make([]*string, len(f.Values))
Expand All @@ -71,7 +68,7 @@ func buildEC2Filters(inputFilters []awsproviderv1.Filter) []*ec2.Filter {
return filters
}

func getSecurityGroupsIDs(securityGroups []awsproviderv1.AWSResourceReference, client awsclient.Client) ([]*string, error) {
func getSecurityGroupsIDs(securityGroups []machinev1.AWSResourceReference, client awsclient.Client) ([]*string, error) {
var securityGroupIDs []*string
for _, g := range securityGroups {
// ID has priority
Expand Down Expand Up @@ -102,13 +99,13 @@ func getSecurityGroupsIDs(securityGroups []awsproviderv1.AWSResourceReference, c
return securityGroupIDs, nil
}

func getSubnetIDs(machine runtimeclient.ObjectKey, subnet awsproviderv1.AWSResourceReference, availabilityZone string, client awsclient.Client) ([]*string, error) {
func getSubnetIDs(machine runtimeclient.ObjectKey, subnet machinev1.AWSResourceReference, availabilityZone string, client awsclient.Client) ([]*string, error) {
var subnetIDs []*string
// ID has priority
if subnet.ID != nil {
subnetIDs = append(subnetIDs, subnet.ID)
} else {
var filters []awsproviderv1.Filter
var filters []machinev1.Filter
if availabilityZone != "" {
// Improve error logging for better user experience.
// Otherwise, during the process of minimizing API calls, this is a good
Expand All @@ -125,7 +122,7 @@ func getSubnetIDs(machine runtimeclient.ObjectKey, subnet awsproviderv1.AWSResou
klog.Errorf("error describing availability zones: %v", err)
return nil, fmt.Errorf("error describing availability zones: %v", err)
}
filters = append(filters, awsproviderv1.Filter{Name: "availabilityZone", Values: []string{availabilityZone}})
filters = append(filters, machinev1.Filter{Name: "availabilityZone", Values: []string{availabilityZone}})
}
filters = append(filters, subnet.Filters...)
klog.Info("Describing subnets based on filters")
Expand Down Expand Up @@ -153,7 +150,7 @@ func getSubnetIDs(machine runtimeclient.ObjectKey, subnet awsproviderv1.AWSResou
return subnetIDs, nil
}

func getAMI(machine runtimeclient.ObjectKey, AMI awsproviderv1.AWSResourceReference, client awsclient.Client) (*string, error) {
func getAMI(machine runtimeclient.ObjectKey, AMI machinev1.AWSResourceReference, client awsclient.Client) (*string, error) {
if AMI.ID != nil {
amiID := AMI.ID
klog.Infof("Using AMI %s", *amiID)
Expand Down Expand Up @@ -200,7 +197,7 @@ func getAMI(machine runtimeclient.ObjectKey, AMI awsproviderv1.AWSResourceRefere
return nil, fmt.Errorf("AMI ID or AMI filters need to be specified")
}

func getBlockDeviceMappings(machine runtimeclient.ObjectKey, blockDeviceMappingSpecs []awsproviderv1.BlockDeviceMappingSpec, AMI string, client awsclient.Client) ([]*ec2.BlockDeviceMapping, error) {
func getBlockDeviceMappings(machine runtimeclient.ObjectKey, blockDeviceMappingSpecs []machinev1.BlockDeviceMappingSpec, AMI string, client awsclient.Client) ([]*ec2.BlockDeviceMapping, error) {
blockDeviceMappings := make([]*ec2.BlockDeviceMapping, 0)

if len(blockDeviceMappingSpecs) == 0 {
Expand Down Expand Up @@ -273,7 +270,7 @@ func getBlockDeviceMappings(machine runtimeclient.ObjectKey, blockDeviceMappingS
return blockDeviceMappings, nil
}

func launchInstance(machine *machinev1.Machine, machineProviderConfig *awsproviderv1.AWSMachineProviderConfig, userData []byte, client awsclient.Client, infra *configv1.Infrastructure) (*ec2.Instance, error) {
func launchInstance(machine *machinev1.Machine, machineProviderConfig *machinev1.AWSMachineProviderConfig, userData []byte, client awsclient.Client, infra *configv1.Infrastructure) (*ec2.Instance, error) {
machineKey := runtimeclient.ObjectKey{
Name: machine.Name,
Namespace: machine.Namespace,
Expand Down Expand Up @@ -348,7 +345,7 @@ func launchInstance(machine *machinev1.Machine, machineProviderConfig *awsprovid
switch instanceTenancy {
case "":
// Do nothing when not set
case awsproviderv1.DefaultTenancy, awsproviderv1.DedicatedTenancy, awsproviderv1.HostTenancy:
case machinev1.DefaultTenancy, machinev1.DedicatedTenancy, machinev1.HostTenancy:
if placement == nil {
placement = &ec2.Placement{}
}
Expand All @@ -357,9 +354,9 @@ func launchInstance(machine *machinev1.Machine, machineProviderConfig *awsprovid
default:
return nil, mapierrors.CreateMachine("invalid instance tenancy: %s. Allowed options are: %s,%s,%s",
instanceTenancy,
awsproviderv1.DefaultTenancy,
awsproviderv1.DedicatedTenancy,
awsproviderv1.HostTenancy)
machinev1.DefaultTenancy,
machinev1.DedicatedTenancy,
machinev1.HostTenancy)
}

inputConfig := ec2.RunInstancesInput{
Expand Down Expand Up @@ -412,7 +409,7 @@ func launchInstance(machine *machinev1.Machine, machineProviderConfig *awsprovid
}

// buildTagList compile a list of ec2 tags from machine provider spec and infrastructure object platform spec
func buildTagList(machineName string, clusterID string, machineTags []awsproviderv1.TagSpecification, infra *configv1.Infrastructure) []*ec2.Tag {
func buildTagList(machineName string, clusterID string, machineTags []machinev1.TagSpecification, infra *configv1.Infrastructure) []*ec2.Tag {
rawTagList := []*ec2.Tag{}

mergedTags := mergeInfrastructureAndMachineSpecTags(machineTags, infra)
Expand All @@ -433,16 +430,16 @@ func buildTagList(machineName string, clusterID string, machineTags []awsprovide

// mergeInfrastructureAndMachineSpecTags merge list of tags from machine provider spec and Infrastructure object platform spec.
// Machine tags have precedence over Infrastructure
func mergeInfrastructureAndMachineSpecTags(machineSpecTags []awsproviderv1.TagSpecification, infra *configv1.Infrastructure) []awsproviderv1.TagSpecification {
func mergeInfrastructureAndMachineSpecTags(machineSpecTags []machinev1.TagSpecification, infra *configv1.Infrastructure) []machinev1.TagSpecification {
if infra == nil || infra.Status.PlatformStatus == nil || infra.Status.PlatformStatus.AWS == nil || infra.Status.PlatformStatus.AWS.ResourceTags == nil {
return machineSpecTags
}

mergedList := []awsproviderv1.TagSpecification{}
mergedList := []machinev1.TagSpecification{}
mergedList = append(mergedList, machineSpecTags...)

for _, tag := range infra.Status.PlatformStatus.AWS.ResourceTags {
mergedList = append(mergedList, awsproviderv1.TagSpecification{Name: tag.Key, Value: tag.Value})
mergedList = append(mergedList, machinev1.TagSpecification{Name: tag.Key, Value: tag.Value})
}

return mergedList
Expand Down Expand Up @@ -479,7 +476,7 @@ func sortInstances(instances []*ec2.Instance) {
sort.Sort(instanceList(instances))
}

func getInstanceMarketOptionsRequest(providerConfig *awsproviderv1.AWSMachineProviderConfig) *ec2.InstanceMarketOptionsRequest {
func getInstanceMarketOptionsRequest(providerConfig *machinev1.AWSMachineProviderConfig) *ec2.InstanceMarketOptionsRequest {
if providerConfig.SpotMarketOptions == nil {
// Instance is not a Spot instance
return nil
Expand Down
Loading

0 comments on commit acf692a

Please sign in to comment.