Skip to content

Commit

Permalink
feat: e2e test updates
Browse files Browse the repository at this point in the history
- remove unused functions
- add new required functions
- rename of one mhc remediation test

Signed-off-by: Chris Privitere <[email protected]>
  • Loading branch information
cprivitere committed Oct 26, 2023
1 parent c55796f commit 0dddf1a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 33 deletions.
4 changes: 2 additions & 2 deletions test/e2e/capi_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ var _ = Describe("[General] Running the Cluster API E2E tests", func() {
// - capi_e2e.MachineDeploymentRolloutSpec

Context("Running the mhc-remediation spec", func() {
capi_e2e.MachineRemediationSpec(ctx, func() capi_e2e.MachineRemediationSpecInput {
return capi_e2e.MachineRemediationSpecInput{
capi_e2e.MachineDeploymentRemediationSpec(ctx, func() capi_e2e.MachineDeploymentRemediationSpecInput {
return capi_e2e.MachineDeploymentRemediationSpecInput{
E2EConfig: e2eConfig,
ClusterctlConfigPath: clusterctlConfigPath,
BootstrapClusterProxy: bootstrapClusterProxy,
Expand Down
42 changes: 11 additions & 31 deletions test/e2e/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@ import (
"net/url"
"os"
goruntime "runtime"
"strings"

"github.com/blang/semver"
"github.com/docker/distribution/reference"
metal "github.com/equinix-labs/metal-go/metal/v1"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
Expand All @@ -45,7 +42,7 @@ import (
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
"sigs.k8s.io/cluster-api/test/framework"
"sigs.k8s.io/cluster-api/test/infrastructure/container"
capiversionutil "sigs.k8s.io/cluster-api/util/version"
"sigs.k8s.io/controller-runtime/pkg/cache"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/apiutil"
)
Expand Down Expand Up @@ -124,6 +121,11 @@ func (w *wrappedClusterProxy) GetRESTConfig() *rest.Config {
return w.clusterProxy.GetRESTConfig()
}

// GetCache returns a controller-runtime cache to create informer from.
func (w *wrappedClusterProxy) GetCache(ctx context.Context) cache.Cache {
return w.clusterProxy.GetCache(ctx)
}

// GetLogCollector returns the machine log collector for the Kubernetes cluster.
func (w *wrappedClusterProxy) GetLogCollector() framework.ClusterLogCollector {
return w.clusterProxy.GetLogCollector()
Expand Down Expand Up @@ -366,37 +368,15 @@ func (wc *wrappedClient) RESTMapper() meta.RESTMapper {
return wc.client.RESTMapper()
}

// SubResource returns the sub resource this client is using.
func (wc *wrappedClient) SubResource(subResource string) client.SubResourceClient {
return wc.client.SubResource(subResource)
}

func (wc *wrappedClient) Scheme() *runtime.Scheme {
return wc.client.Scheme()
}

func (wc *wrappedClient) Status() client.StatusWriter {
return wc.client.Status()
}

func containerImageGTE(container corev1.Container, version semver.Version) (bool, error) {
ref, err := reference.ParseNormalizedNamed(container.Image)
if err != nil {
return false, fmt.Errorf("failed to parse container reference %s: %w", container.Image, err)
}

ref = reference.TagNameOnly(ref)
tagged, _ := ref.(reference.Tagged)
tag := tagged.Tag()

if tag == "latest" {
return false, nil
}

// If the image tag starts with sha-, assume we are running in CI and can assume the version is new enough
if strings.HasPrefix(tag, "sha-") {
return false, nil
}

imageVersion, err := capiversionutil.ParseMajorMinorPatchTolerant(tag)
if err != nil {
return false, fmt.Errorf("failed to get version from image: %w", err)
}

return imageVersion.GTE(version), nil
}

0 comments on commit 0dddf1a

Please sign in to comment.