Repository: kubernetes-sigs/cluster-api-provider-aws
Pull request #2971 (2021-11-17 23:53:09)

Bump cluster-api in e2e tests + fix K8s version
/kind failing-test

Downgrade K8s version to the latest kind node 1.22.2




```release-note
NONE
```


k8s-ci-robot: @sedefsavas: This issue is currently awaiting triage.

If CAPA/CAPI contributors determines this is a relevant issue, they will accept it by applying the `triage/accepted` label and provide further guidance.

The `triage/accepted` label can be added by org members by writing `/triage accepted` in a comment.


<details>

Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md).  If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository.
</details>
k8s-ci-robot: [APPROVALNOTIFIER] This PR is **NOT APPROVED**

This pull-request has been approved by:
To complete the [pull request process](https://git.k8s.io/community/contributors/guide/owners.md#the-code-review-process), please ask for approval from **sedefsavas** after the PR has been reviewed.

The full list of commands accepted by this bot can be found [here](https://go.k8s.io/bot-commands?repo=kubernetes-sigs%2Fcluster-api-provider-aws).

<details open>
Needs approval from an approver in each of these files:

- **[OWNERS](https://github.com/kubernetes-sigs/cluster-api-provider-aws/blob/main/OWNERS)**

Approvers can indicate their approval by writing `/approve` in a comment
Approvers can cancel approval by writing `/approve cancel` in a comment
</details>
<!-- META={"approvers":["sedefsavas"]} -->

Patch:
diff --git a/controllers/awsmachine_controller.go b/controllers/awsmachine_controller.go
index 2324797cf..1fd51a1ae 100644
--- a/controllers/awsmachine_controller.go
+++ b/controllers/awsmachine_controller.go
@@ -323,8 +323,8 @@ func (r *AWSMachineReconciler) reconcileDelete(machineScope *scope.MachineScope,
 	}
 
 	instance, err := r.findInstance(machineScope, ec2Service)
-	if err != nil && err != ec2.ErrInstanceNotFoundByID {
-		machineScope.Error(err, "query to find instance failed")
+	if err != nil {
+		machineScope.Error(err, "unable to find instance")
 		return ctrl.Result{}, err
 	}
 
@@ -426,34 +426,29 @@ func (r *AWSMachineReconciler) reconcileDelete(machineScope *scope.MachineScope,
 	return ctrl.Result{}, nil
 }
 
-// findInstance queries the EC2 apis and retrieves the instance if it exists.
-// If providerID is empty, finds instance by tags and if it cannot be found, returns empty instance with nil error.
-// If providerID is set, either finds the instance by ID or returns error.
+// findInstance queries the EC2 apis and retrieves the instance if it exists, returns nil otherwise.
 func (r *AWSMachineReconciler) findInstance(scope *scope.MachineScope, ec2svc services.EC2MachineInterface) (*infrav1.Instance, error) {
-	var instance *infrav1.Instance
-
 	// Parse the ProviderID.
 	pid, err := noderefutil.NewProviderID(scope.GetProviderID())
-	if err != nil {
-		if !errors.Is(err, noderefutil.ErrEmptyProviderID) {
-			return nil, errors.Wrapf(err, "failed to parse Spec.ProviderID")
-		}
-		// If the ProviderID is empty, try to query the instance using tags.
-		// If an instance cannot be found, GetRunningInstanceByTags returns empty instance with nil error.
-		instance, err = ec2svc.GetRunningInstanceByTags(scope)
-		if err != nil {
-			return nil, errors.Wrapf(err, "failed to query AWSMachine instance by tags")
-		}
-	} else {
-		// If the ProviderID is populated, describe the instance using the ID.
-		// InstanceIfExists() returns error (ErrInstanceNotFoundByID or ErrDescribeInstance) if the instance could not be found.
-		instance, err = ec2svc.InstanceIfExists(pointer.StringPtr(pid.ID()))
+	if err != nil && !errors.Is(err, noderefutil.ErrEmptyProviderID) {
+		return nil, errors.Wrapf(err, "failed to parse Spec.ProviderID")
+	}
+
+	// If the ProviderID is populated, describe the instance using the ID.
+	if err == nil {
+		instance, err := ec2svc.InstanceIfExists(pointer.StringPtr(pid.ID()))
 		if err != nil {
-			return nil, err
+			return nil, errors.Wrapf(err, "failed to query AWSMachine instance")
 		}
+		return instance, nil
+	}
+
+	// If the ProviderID is empty, try to query the instance using tags.
+	instance, err := ec2svc.GetRunningInstanceByTags(scope)
+	if err != nil {
+		return nil, errors.Wrapf(err, "failed to query AWSMachine instance by tags")
 	}
 
-	// The only case where the instance is nil here is when the providerId is empty and instance could not be found by tags.
 	return instance, nil
 }
 
@@ -506,7 +501,7 @@ func (r *AWSMachineReconciler) reconcileNormal(_ context.Context, machineScope *
 		return ctrl.Result{}, err
 	}
 
-	// Create new instance since providerId is nil and instance could not be found by tags.
+	// Create new instance
 	if instance == nil {
 		// Avoid a flickering condition between InstanceProvisionStarted and InstanceProvisionFailed if there's a persistent failure with createInstance
 		if conditions.GetReason(machineScope.AWSMachine, infrav1.InstanceReadyCondition) != infrav1.InstanceProvisionFailedReason {
diff --git a/pkg/cloud/services/ec2/errors.go b/pkg/cloud/services/ec2/errors.go
deleted file mode 100644
index 3d008e1c9..000000000
--- a/pkg/cloud/services/ec2/errors.go
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
-Copyright 2021 The Kubernetes 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 ec2
-
-import "errors"
-
-var (
-	// ErrInstanceNotFoundByID defines an error for when the instance with the provided provider ID is missing.
-	ErrInstanceNotFoundByID = errors.New("failed to find instance by id")
-
-	// ErrDescribeInstance defines an error for when AWS SDK returns error when describing instances.
-	ErrDescribeInstance = errors.New("failed to describe instance by id")
-)
diff --git a/pkg/cloud/services/ec2/instances.go b/pkg/cloud/services/ec2/instances.go
index 894adb485..7037e6475 100644
--- a/pkg/cloud/services/ec2/instances.go
+++ b/pkg/cloud/services/ec2/instances.go
@@ -75,8 +75,7 @@ func (s *Service) GetRunningInstanceByTags(scope *scope.MachineScope) (*infrav1.
 	return nil, nil
 }
 
-// InstanceIfExists returns the existing instance by id and errors if it cannot find the instance(ErrInstanceNotFoundByID) or API call fails (ErrDescribeInstance).
-// Returns empty instance with nil error, only when providerID is nil.
+// InstanceIfExists returns the existing instance or nothing if it doesn't exist.
 func (s *Service) InstanceIfExists(id *string) (*infrav1.Instance, error) {
 	if id == nil {
 		s.scope.Info("Instance does not have an instance id")
@@ -92,20 +91,17 @@ func (s *Service) InstanceIfExists(id *string) (*infrav1.Instance, error) {
 	out, err := s.EC2Client.DescribeInstances(input)
 	switch {
 	case awserrors.IsNotFound(err):
-		record.Eventf(s.scope.InfraCluster(), "FailedFindInstances", "failed to find instance by providerId %q: %v", *id, err)
-		return nil, ErrInstanceNotFoundByID
+		return nil, nil
 	case err != nil:
 		record.Eventf(s.scope.InfraCluster(), "FailedDescribeInstances", "failed to describe instance %q: %v", *id, err)
-		return nil, ErrDescribeInstance
+		return nil, errors.Wrapf(err, "failed to describe instance: %q", *id)
 	}
 
 	if len(out.Reservations) > 0 && len(out.Reservations[0].Instances) > 0 {
 		return s.SDKToInstance(out.Reservations[0].Instances[0])
-	} else {
-		// Failed to find instance with provider id.
-		record.Eventf(s.scope.InfraCluster(), "FailedFindInstances", "failed to find instance by providerId %q: %v", *id, err)
-		return nil, ErrInstanceNotFoundByID
 	}
+
+	return nil, nil
 }
 
 // CreateInstance runs an ec2 instance.


Test patch:
diff --git a/pkg/cloud/services/ec2/instances_test.go b/pkg/cloud/services/ec2/instances_test.go
index 934b692a1..99432542a 100644
--- a/pkg/cloud/services/ec2/instances_test.go
+++ b/pkg/cloud/services/ec2/instances_test.go
@@ -61,8 +61,8 @@ func TestInstanceIfExists(t *testing.T) {
 					Return(nil, awserrors.NewNotFound("not found"))
 			},
 			check: func(instance *infrav1.Instance, err error) {
-				if err == nil {
-					t.Fatalf("expects error when instance could not be found: %v", err)
+				if err != nil {
+					t.Fatalf("did not expect error: %v", err)
 				}
 
 				if instance != nil {
@@ -80,8 +80,8 @@ func TestInstanceIfExists(t *testing.T) {
 					Return(nil, awserr.New(awserrors.InvalidInstanceID, "does not exist", nil))
 			},
 			check: func(instance *infrav1.Instance, err error) {
-				if err == nil {
-					t.Fatalf("expects error when DescribeInstances returns error: %v", err)
+				if err != nil {
+					t.Fatalf("did not expect error: %v", err)
 				}
 
 				if instance != nil {
diff --git a/test/e2e/data/e2e_conf.yaml b/test/e2e/data/e2e_conf.yaml
index 61f012437..94a1a145e 100644
--- a/test/e2e/data/e2e_conf.yaml
+++ b/test/e2e/data/e2e_conf.yaml
@@ -27,11 +27,11 @@ images:
     loadBehavior: tryLoad
   - name: quay.io/jetstack/cert-manager-controller:v1.5.3
     loadBehavior: tryLoad
-  - name: k8s.gcr.io/cluster-api/cluster-api-controller:v1.0.0
+  - name: k8s.gcr.io/cluster-api/cluster-api-controller:v1.0.1
     loadBehavior: tryLoad
-  - name: k8s.gcr.io/cluster-api/kubeadm-bootstrap-controller:v1.0.0
+  - name: k8s.gcr.io/cluster-api/kubeadm-bootstrap-controller:v1.0.1
     loadBehavior: tryLoad
-  - name: k8s.gcr.io/cluster-api/kubeadm-control-plane-controller:v1.0.0
+  - name: k8s.gcr.io/cluster-api/kubeadm-control-plane-controller:v1.0.1
     loadBehavior: tryLoad
 
 providers:
@@ -60,8 +60,8 @@ providers:
             new: "imagePullPolicy: IfNotPresent"
           - old: --metrics-bind-addr=127.0.0.1:8080
             new: --metrics-bind-addr=:8080
-      - name: v1.0.0
-        value: "https://github.com/kubernetes-sigs/cluster-api/releases/download/v1.0.0/core-components.yaml"
+      - name: v1.0.1
+        value: "https://github.com/kubernetes-sigs/cluster-api/releases/download/v1.0.1/core-components.yaml"
         type: "url"
         contract: v1beta1
         files:
@@ -96,8 +96,8 @@ providers:
             new: "imagePullPolicy: IfNotPresent"
           - old: --metrics-bind-addr=127.0.0.1:8080
             new: --metrics-bind-addr=:8080
-      - name: v1.0.0
-        value: "https://github.com/kubernetes-sigs/cluster-api/releases/download/v1.0.0/bootstrap-components.yaml"
+      - name: v1.0.1
+        value: "https://github.com/kubernetes-sigs/cluster-api/releases/download/v1.0.1/bootstrap-components.yaml"
         type: "url"
         contract: v1beta1
         files:
@@ -134,8 +134,8 @@ providers:
             new: "imagePullPolicy: IfNotPresent"
           - old: --metrics-bind-addr=127.0.0.1:8080
             new: --metrics-bind-addr=:8080
-      - name: v1.0.0
-        value: "https://github.com/kubernetes-sigs/cluster-api/releases/download/v1.0.0/control-plane-components.yaml"
+      - name: v1.0.1
+        value: "https://github.com/kubernetes-sigs/cluster-api/releases/download/v1.0.1/control-plane-components.yaml"
         type: "url"
         contract: v1beta1
         files:
@@ -162,7 +162,7 @@ providers:
         files:
           - sourcePath: "./shared/v1alpha4_provider/metadata.yaml"
           - sourcePath: "./infrastructure-aws/capi-upgrades/v1alpha4/cluster-template.yaml"
-      - name: v1.0.0
+      - name: v1.0.1
         # Use manifest from source files
         value: ../../../config/default
         contract: v1beta1
@@ -202,8 +202,8 @@ variables:
   # The following Kubernetes versions should be the latest versions with already published kindest/node images.
   # This avoids building node images in the default case which improves the test duration significantly.
   KUBERNETES_VERSION_MANAGEMENT: "v1.22.2"
-  KUBERNETES_VERSION: "v1.22.3"
-  KUBERNETES_VERSION_UPGRADE_TO: "v1.22.3"
+  KUBERNETES_VERSION: "v1.22.2"
+  KUBERNETES_VERSION_UPGRADE_TO: "v1.22.2"
   KUBERNETES_VERSION_UPGRADE_FROM: "v1.21.6"
   CNI: "../../data/cni/calico.yaml"
   EXP_CLUSTER_RESOURCE_SET: "true"
@@ -211,7 +211,7 @@ variables:
   AWS_CONTROL_PLANE_MACHINE_TYPE: t3.large
   AWS_NODE_MACHINE_TYPE: t3.large
   AWS_SSH_KEY_NAME: "cluster-api-provider-aws-sigs-k8s-io"
-  CONFORMANCE_CI_ARTIFACTS_KUBERNETES_VERSION: "v1.22.3"
+  CONFORMANCE_CI_ARTIFACTS_KUBERNETES_VERSION: "v1.22.2"
   CONFORMANCE_WORKER_MACHINE_COUNT: "5"
   CONFORMANCE_CONTROL_PLANE_MACHINE_COUNT: "1"
   EXP_MACHINE_POOL: "true"
@@ -224,7 +224,7 @@ variables:
   INIT_WITH_BINARY_V1ALPHA4: "https://github.com/kubernetes-sigs/cluster-api/releases/download/v0.4.4/clusterctl-{OS}-{ARCH}"
     # INIT_WITH_KUBERNETES_VERSION are only used by the clusterctl upgrade test to initialize
   # the management cluster to be upgraded.
-  INIT_WITH_KUBERNETES_VERSION: "v1.22.3"
+  INIT_WITH_KUBERNETES_VERSION: "v1.22.2"
 
 intervals:
   default/wait-cluster: ["25m", "10s"]
diff --git a/test/e2e/data/e2e_eks_conf.yaml b/test/e2e/data/e2e_eks_conf.yaml
index 4243c8b5f..90a2cca40 100644
--- a/test/e2e/data/e2e_eks_conf.yaml
+++ b/test/e2e/data/e2e_eks_conf.yaml
@@ -25,11 +25,11 @@ images:
     loadBehavior: tryLoad
   - name: quay.io/jetstack/cert-manager-controller:v1.5.0
     loadBehavior: tryLoad
-  - name: k8s.gcr.io/cluster-api/kubeadm-control-plane-controller:v1.0.0
+  - name: k8s.gcr.io/cluster-api/kubeadm-control-plane-controller:v1.0.1
     loadBehavior: tryLoad
-  - name: k8s.gcr.io/cluster-api/kubeadm-bootstrap-controller:v1.0.0
+  - name: k8s.gcr.io/cluster-api/kubeadm-bootstrap-controller:v1.0.1
     loadBehavior: tryLoad
-  - name: k8s.gcr.io/cluster-api/cluster-api-controller:v1.0.0
+  - name: k8s.gcr.io/cluster-api/cluster-api-controller:v1.0.1
     loadBehavior: tryLoad
 
 providers:
@@ -58,8 +58,8 @@ providers:
             new: "imagePullPolicy: IfNotPresent"
           - old: --metrics-bind-addr=127.0.0.1:8080
             new: --metrics-bind-addr=:8080
-      - name: v1.0.0
-        value: "https://github.com/kubernetes-sigs/cluster-api/releases/download/v1.0.0/core-components.yaml"
+      - name: v1.0.1
+        value: "https://github.com/kubernetes-sigs/cluster-api/releases/download/v1.0.1/core-components.yaml"
         type: "url"
         contract: v1beta1
         files:
@@ -94,8 +94,8 @@ providers:
             new: "imagePullPolicy: IfNotPresent"
           - old: --metrics-bind-addr=127.0.0.1:8080
             new: --metrics-bind-addr=:8080
-      - name: v1.0.0
-        value: "https://github.com/kubernetes-sigs/cluster-api/releases/download/v1.0.0/bootstrap-components.yaml"
+      - name: v1.0.1
+        value: "https://github.com/kubernetes-sigs/cluster-api/releases/download/v1.0.1/bootstrap-components.yaml"
         type: "url"
         contract: v1beta1
         files:
@@ -131,8 +131,8 @@ providers:
             new: "imagePullPolicy: IfNotPresent"
           - old: --metrics-bind-addr=127.0.0.1:8080
             new: --metrics-bind-addr=:8080
-      - name: v1.0.0
-        value: "https://github.com/kubernetes-sigs/cluster-api/releases/download/v1.0.0/control-plane-components.yaml"
+      - name: v1.0.1
+        value: "https://github.com/kubernetes-sigs/cluster-api/releases/download/v1.0.1/control-plane-components.yaml"
         type: "url"
         contract: v1beta1
         files: