Skip to content

Commit

Permalink
Validate machine status in e2e
Browse files Browse the repository at this point in the history
  • Loading branch information
spangenberg committed Nov 9, 2018
1 parent 56b0f59 commit 0f1f5d9
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 17 deletions.
5 changes: 1 addition & 4 deletions pkg/cloud/aws/actuators/machine/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,7 @@ func ProviderConfigFromMachine(machine *clusterv1.Machine) (*providerconfigv1.AW
// ProviderStatusFromMachine gets the machine provider status from the specified machine.
func ProviderStatusFromMachine(codec codec, m *clusterv1.Machine) (*providerconfigv1.AWSMachineProviderStatus, error) {
status := &providerconfigv1.AWSMachineProviderStatus{}
var err error
if m.Status.ProviderStatus != nil {
err = codec.DecodeProviderStatus(m.Status.ProviderStatus, status)
}
err := codec.DecodeProviderStatus(m.Status.ProviderStatus, status)
return status, err
}

Expand Down
19 changes: 6 additions & 13 deletions test/machines/machines_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/ec2"

machineutils "sigs.k8s.io/cluster-api-provider-aws/pkg/cloud/aws/actuators/machine"
awsclient "sigs.k8s.io/cluster-api-provider-aws/pkg/cloud/aws/client"
)

Expand All @@ -36,19 +37,6 @@ func TestCart(t *testing.T) {
RunSpecs(t, "Machine Suite")
}

func createSecretAndWait(f *framework.Framework, secret *apiv1.Secret) {
_, err := f.KubeClient.CoreV1().Secrets(secret.Namespace).Create(secret)
Expect(err).NotTo(HaveOccurred())

err = wait.Poll(framework.PollInterval, framework.PoolTimeout, func() (bool, error) {
if _, err := f.KubeClient.CoreV1().Secrets(secret.Namespace).Get(secret.Name, metav1.GetOptions{}); err != nil {
return false, nil
}
return true, nil
})
Expect(err).NotTo(HaveOccurred())
}

var _ = framework.SigKubeDescribe("Machines", func() {
var testNamespace *apiv1.Namespace
f, err := framework.NewFramework()
Expand Down Expand Up @@ -204,6 +192,11 @@ var _ = framework.SigKubeDescribe("Machines", func() {
}))
})

By("Checking machine status", func() {
condition := getMachineCondition(f, testMachine)
Expect(condition.Reason).To(Equal(machineutils.MachineCreationSucceeded))
})

f.DeleteMachineAndWait(testMachine, acw)
})

Expand Down
46 changes: 46 additions & 0 deletions test/machines/utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package machines

import (
. "github.com/onsi/gomega"
apiv1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/wait"
clusterv1alpha1 "sigs.k8s.io/cluster-api/pkg/apis/cluster/v1alpha1"

"github.com/openshift/cluster-api-actuator-pkg/pkg/e2e/framework"

providerconfigv1 "sigs.k8s.io/cluster-api-provider-aws/pkg/apis/awsproviderconfig/v1alpha1"
machineutils "sigs.k8s.io/cluster-api-provider-aws/pkg/cloud/aws/actuators/machine"
)

func createSecretAndWait(f *framework.Framework, secret *apiv1.Secret) {
_, err := f.KubeClient.CoreV1().Secrets(secret.Namespace).Create(secret)
Expect(err).NotTo(HaveOccurred())

err = wait.Poll(framework.PollInterval, framework.PoolTimeout, func() (bool, error) {
if _, err := f.KubeClient.CoreV1().Secrets(secret.Namespace).Get(secret.Name, metav1.GetOptions{}); err != nil {
return false, nil
}
return true, nil
})
Expect(err).NotTo(HaveOccurred())
}

func getMachineProviderStatus(f *framework.Framework, machine *clusterv1alpha1.Machine) *providerconfigv1.AWSMachineProviderStatus {
machine, err := f.CAPIClient.ClusterV1alpha1().Machines(machine.Namespace).Get(machine.Name, metav1.GetOptions{})
Expect(err).NotTo(HaveOccurred())

codec, err := providerconfigv1.NewCodec()
Expect(err).NotTo(HaveOccurred())

machineProviderStatus, err := machineutils.ProviderStatusFromMachine(codec, machine)
Expect(err).NotTo(HaveOccurred())

return machineProviderStatus
}

func getMachineCondition(f *framework.Framework, machine *clusterv1alpha1.Machine) providerconfigv1.AWSMachineProviderCondition {
conditions := getMachineProviderStatus(f, machine).Conditions
Expect(len(conditions)).To(Equal(1), "ambiguous conditions: %#v", conditions)
return conditions[0]
}

0 comments on commit 0f1f5d9

Please sign in to comment.