Skip to content

Commit 05fdd90

Browse files
committed
Revert changed public APIs and adapt internally to v1beta2
Signed-off-by: Borja Clemente <bclement@redhat.com>
1 parent 8a317a9 commit 05fdd90

File tree

10 files changed

+48
-32
lines changed

10 files changed

+48
-32
lines changed

api/v1beta1/zz_generated.conversion.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v1beta2/awsmachine_types.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2121

2222
clusterv1beta1 "sigs.k8s.io/cluster-api/api/core/v1beta1" //nolint:staticcheck
23-
clusterv1 "sigs.k8s.io/cluster-api/api/core/v1beta2"
2423
)
2524

2625
const (
@@ -415,7 +414,7 @@ type AWSMachineStatus struct {
415414
Interruptible bool `json:"interruptible,omitempty"`
416415

417416
// Addresses contains the AWS instance associated addresses.
418-
Addresses []clusterv1.MachineAddress `json:"addresses,omitempty"`
417+
Addresses []clusterv1beta1.MachineAddress `json:"addresses,omitempty"`
419418

420419
// InstanceState is the state of the AWS instance for this machine.
421420
// +optional

api/v1beta2/tags.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323
"k8s.io/apimachinery/pkg/types"
2424
"k8s.io/apimachinery/pkg/util/validation/field"
2525

26-
clusterv1 "sigs.k8s.io/cluster-api/api/core/v1beta2"
26+
clusterv1beta1 "sigs.k8s.io/cluster-api/api/core/v1beta1" //nolint:staticcheck
2727
)
2828

2929
// Tags defines a map of tags.
@@ -78,7 +78,7 @@ func (t Tags) Validate() []*field.Error {
7878
// Defines the maximum number of user tags which can be created for a specific resource
7979
const maxUserTagsAllowed = 50
8080
var errs field.ErrorList
81-
var userTagCount = len(t)
81+
userTagCount := len(t)
8282
re := regexp.MustCompile(`^[a-zA-Z0-9\s\_\.\:\=\+\-\@\/]*$`)
8383

8484
for k, v := range t {
@@ -239,7 +239,7 @@ type BuildParams struct {
239239

240240
// WithMachineName tags the namespaced machine name
241241
// The machine name will be tagged with key "MachineName".
242-
func (b BuildParams) WithMachineName(m *clusterv1.Machine) BuildParams {
242+
func (b BuildParams) WithMachineName(m *clusterv1beta1.Machine) BuildParams {
243243
machineNamespacedName := types.NamespacedName{Namespace: m.Namespace, Name: m.Name}
244244
b.Additional[MachineNameTagKey] = machineNamespacedName.String()
245245
return b

api/v1beta2/types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121

2222
"k8s.io/apimachinery/pkg/util/sets"
2323

24-
clusterv1 "sigs.k8s.io/cluster-api/api/core/v1beta2"
24+
clusterv1beta1 "sigs.k8s.io/cluster-api/api/core/v1beta1" //nolint:staticcheck
2525
)
2626

2727
const (
@@ -192,7 +192,7 @@ type Instance struct {
192192
IAMProfile string `json:"iamProfile,omitempty"`
193193

194194
// Addresses contains the AWS instance associated addresses.
195-
Addresses []clusterv1.MachineAddress `json:"addresses,omitempty"`
195+
Addresses []clusterv1beta1.MachineAddress `json:"addresses,omitempty"`
196196

197197
// The private IPv4 address assigned to the instance.
198198
PrivateIP *string `json:"privateIp,omitempty"`

api/v1beta2/zz_generated.deepcopy.go

Lines changed: 2 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bootstrap/eks/api/v1beta1/condition_consts.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ limitations under the License.
1616

1717
package v1beta1
1818

19-
import clusterv1 "sigs.k8s.io/cluster-api/api/core/v1beta2"
19+
import clusterv1beta1 "sigs.k8s.io/cluster-api/api/core/v1beta1" //nolint:staticcheck
2020

2121
// Conditions and condition Reasons for the EKSConfig object
2222
// FROM: https://github.com/kubernetes-sigs/cluster-api/blob/main/bootstrap/kubeadm/api/v1beta1/condition_consts.go
@@ -27,7 +27,7 @@ const (
2727
// NOTE: When the DataSecret generation starts the process completes immediately and within the
2828
// same reconciliation, so the user will always see a transition from Wait to Generated without having
2929
// evidence that BootstrapSecret generation is started/in progress.
30-
DataSecretAvailableCondition clusterv1.ConditionType = "DataSecretAvailable"
30+
DataSecretAvailableCondition clusterv1beta1.ConditionType = "DataSecretAvailable"
3131

3232
// DataSecretGenerationFailedReason (Severity=Warning) documents a EKSConfig controller detecting
3333
// an error while generating a data secret; those kind of errors are usually due to misconfigurations

pkg/cloud/scope/machine.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ func (m *MachineScope) SetSecretCount(i int32) {
259259
}
260260

261261
// SetAddresses sets the AWSMachine address status.
262-
func (m *MachineScope) SetAddresses(addrs []clusterv1.MachineAddress) {
262+
func (m *MachineScope) SetAddresses(addrs []clusterv1beta1.MachineAddress) {
263263
m.AWSMachine.Status.Addresses = addrs
264264
}
265265

pkg/cloud/services/ec2/bastion_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import (
3434
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/cloud/filter"
3535
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/cloud/scope"
3636
"sigs.k8s.io/cluster-api-provider-aws/v2/test/mocks"
37+
clusterv1beta1 "sigs.k8s.io/cluster-api/api/core/v1beta1" //nolint:staticcheck
3738
clusterv1 "sigs.k8s.io/cluster-api/api/core/v1beta2"
3839
)
3940

@@ -419,7 +420,7 @@ func TestServiceReconcileBastion(t *testing.T) {
419420
SubnetID: "subnet-1",
420421
ImageID: "ubuntu-ami-id-latest",
421422
IAMProfile: "foo",
422-
Addresses: []clusterv1.MachineAddress{},
423+
Addresses: []clusterv1beta1.MachineAddress{},
423424
AvailabilityZone: "us-east-1",
424425
VolumeIDs: []string{"volume-1"},
425426
},
@@ -651,7 +652,7 @@ func TestServiceReconcileBastionUSGOV(t *testing.T) {
651652
SubnetID: "subnet-1",
652653
ImageID: "ubuntu-ami-id-latest",
653654
IAMProfile: "foo",
654-
Addresses: []clusterv1.MachineAddress{},
655+
Addresses: []clusterv1beta1.MachineAddress{},
655656
AvailabilityZone: "us-gov-east-1",
656657
VolumeIDs: []string{"volume-1"},
657658
},

pkg/cloud/services/ec2/instances.go

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"github.com/aws/aws-sdk-go-v2/service/ec2"
2929
"github.com/aws/aws-sdk-go-v2/service/ec2/types"
3030
"github.com/pkg/errors"
31+
"k8s.io/apimachinery/pkg/runtime"
3132
"k8s.io/utils/ptr"
3233

3334
infrav1 "sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta2"
@@ -39,6 +40,7 @@ import (
3940
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/cloud/services/userdata"
4041
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/record"
4142
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/utils"
43+
clusterv1beta1 "sigs.k8s.io/cluster-api/api/core/v1beta1" //nolint:staticcheck
4244
clusterv1 "sigs.k8s.io/cluster-api/api/core/v1beta2"
4345
)
4446

@@ -123,6 +125,20 @@ func (s *Service) CreateInstance(ctx context.Context, scope *scope.MachineScope,
123125
NetworkInterfaceType: scope.AWSMachine.Spec.NetworkInterfaceType,
124126
}
125127

128+
scheme := runtime.NewScheme()
129+
if err := clusterv1beta1.AddToScheme(scheme); err != nil {
130+
return nil, fmt.Errorf("error adding clusterv1beta1 to schema for conversion: %s", err)
131+
}
132+
if err := clusterv1.AddToScheme(scheme); err != nil {
133+
return nil, fmt.Errorf("error adding clusterv1 to schema for conversion: %s", err)
134+
}
135+
136+
var v1beta1Machine clusterv1beta1.Machine
137+
// Convert v1beta1 to v1beta2
138+
if err := scheme.Convert(scope.Machine, &v1beta1Machine, nil); err != nil {
139+
return nil, fmt.Errorf("error converting v1beta2.Machine to v1beta1.Machine: %s", err)
140+
}
141+
126142
// Make sure to use the MachineScope here to get the merger of AWSCluster and AWSMachine tags
127143
additionalTags := scope.AdditionalTags()
128144
input.Tags = infrav1.Build(infrav1.BuildParams{
@@ -131,7 +147,7 @@ func (s *Service) CreateInstance(ctx context.Context, scope *scope.MachineScope,
131147
Name: aws.String(scope.Name()),
132148
Role: aws.String(scope.Role()),
133149
Additional: additionalTags,
134-
}.WithCloudProvider(s.scope.KubernetesClusterName()).WithMachineName(scope.Machine))
150+
}.WithCloudProvider(s.scope.KubernetesClusterName()).WithMachineName(&v1beta1Machine))
135151

136152
var err error
137153

@@ -992,31 +1008,31 @@ func (s *Service) SDKToInstance(v types.Instance) (*infrav1.Instance, error) {
9921008
return i, nil
9931009
}
9941010

995-
func (s *Service) getInstanceAddresses(instance types.Instance) []clusterv1.MachineAddress {
996-
addresses := []clusterv1.MachineAddress{}
1011+
func (s *Service) getInstanceAddresses(instance types.Instance) []clusterv1beta1.MachineAddress {
1012+
addresses := []clusterv1beta1.MachineAddress{}
9971013
// Check if the DHCP Option Set has domain name set
9981014
domainName := s.GetDHCPOptionSetDomainName(s.EC2Client, instance.VpcId)
9991015
for _, eni := range instance.NetworkInterfaces {
10001016
if addr := aws.ToString(eni.PrivateDnsName); addr != "" {
1001-
privateDNSAddress := clusterv1.MachineAddress{
1002-
Type: clusterv1.MachineInternalDNS,
1017+
privateDNSAddress := clusterv1beta1.MachineAddress{
1018+
Type: clusterv1beta1.MachineInternalDNS,
10031019
Address: addr,
10041020
}
10051021
addresses = append(addresses, privateDNSAddress)
10061022

10071023
if domainName != nil {
10081024
// Add secondary private DNS Name with domain name set in DHCP Option Set
1009-
additionalPrivateDNSAddress := clusterv1.MachineAddress{
1010-
Type: clusterv1.MachineInternalDNS,
1025+
additionalPrivateDNSAddress := clusterv1beta1.MachineAddress{
1026+
Type: clusterv1beta1.MachineInternalDNS,
10111027
Address: fmt.Sprintf("%s.%s", strings.Split(privateDNSAddress.Address, ".")[0], *domainName),
10121028
}
10131029
addresses = append(addresses, additionalPrivateDNSAddress)
10141030
}
10151031
}
10161032

10171033
if addr := aws.ToString(eni.PrivateIpAddress); addr != "" {
1018-
privateIPAddress := clusterv1.MachineAddress{
1019-
Type: clusterv1.MachineInternalIP,
1034+
privateIPAddress := clusterv1beta1.MachineAddress{
1035+
Type: clusterv1beta1.MachineInternalIP,
10201036
Address: addr,
10211037
}
10221038
addresses = append(addresses, privateIPAddress)
@@ -1025,16 +1041,16 @@ func (s *Service) getInstanceAddresses(instance types.Instance) []clusterv1.Mach
10251041
// An elastic IP is attached if association is non nil pointer
10261042
if eni.Association != nil {
10271043
if addr := aws.ToString(eni.Association.PublicDnsName); addr != "" {
1028-
publicDNSAddress := clusterv1.MachineAddress{
1029-
Type: clusterv1.MachineExternalDNS,
1044+
publicDNSAddress := clusterv1beta1.MachineAddress{
1045+
Type: clusterv1beta1.MachineExternalDNS,
10301046
Address: addr,
10311047
}
10321048
addresses = append(addresses, publicDNSAddress)
10331049
}
10341050

10351051
if addr := aws.ToString(eni.Association.PublicIp); addr != "" {
1036-
publicIPAddress := clusterv1.MachineAddress{
1037-
Type: clusterv1.MachineExternalIP,
1052+
publicIPAddress := clusterv1beta1.MachineAddress{
1053+
Type: clusterv1beta1.MachineExternalIP,
10381054
Address: addr,
10391055
}
10401056
addresses = append(addresses, publicIPAddress)

pkg/cloud/services/ec2/instances_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import (
4343
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/cloud/scope"
4444
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/cloud/services/userdata"
4545
"sigs.k8s.io/cluster-api-provider-aws/v2/test/mocks"
46+
clusterv1beta1 "sigs.k8s.io/cluster-api/api/core/v1beta1" //nolint:staticcheck
4647
clusterv1 "sigs.k8s.io/cluster-api/api/core/v1beta2"
4748
)
4849

@@ -5321,11 +5322,11 @@ func TestCreateInstance(t *testing.T) {
53215322
g.Expect(len(instance.Addresses)).To(Equal(3))
53225323

53235324
for _, address := range instance.Addresses {
5324-
if address.Type == clusterv1.MachineInternalIP {
5325+
if address.Type == clusterv1beta1.MachineInternalIP {
53255326
g.Expect(address.Address).To(Equal("192.168.1.10"))
53265327
}
53275328

5328-
if address.Type == clusterv1.MachineInternalDNS {
5329+
if address.Type == clusterv1beta1.MachineInternalDNS {
53295330
g.Expect(address.Address).To(Or(Equal("ip-192-168-1-10.ec2.internal"), Equal("ip-192-168-1-10.example.com")))
53305331
}
53315332
}

0 commit comments

Comments
 (0)