Skip to content

Commit

Permalink
Modify CreateDeployment to CreateManagedCluster
Browse files Browse the repository at this point in the history
Signed-off-by: Kyle Squizzato <[email protected]>
  • Loading branch information
squizzi committed Sep 5, 2024
1 parent 1ae09c4 commit 7557577
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion test/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ var _ = Describe("controller", Ordered, func() {
d := managedcluster.GetUnstructured(managedcluster.ProviderAWS, template)
clusterName = d.GetName()

deleteFunc, err = kc.CreateDeployment(context.Background(), d)
deleteFunc, err = kc.CreateManagedCluster(context.Background(), d)
Expect(err).NotTo(HaveOccurred())

By("waiting for infrastructure providers to deploy successfully")
Expand Down
18 changes: 9 additions & 9 deletions test/kubeclient/kubeclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,33 +164,33 @@ func (kc *KubeClient) GetDynamicClient(gvr schema.GroupVersionResource) (dynamic
return client.Resource(gvr).Namespace(kc.Namespace), nil
}

// CreateDeployment creates a deployment.hmc.mirantis.com in the given
// CreateDeployment creates a managedcluster.hmc.mirantis.com in the given
// namespace and returns a DeleteFunc to clean up the deployment.
// The DeleteFunc is a no-op if the deployment has already been deleted.
func (kc *KubeClient) CreateDeployment(
ctx context.Context, deployment *unstructured.Unstructured) (func() error, error) {
kind := deployment.GetKind()
func (kc *KubeClient) CreateManagedCluster(
ctx context.Context, managedcluster *unstructured.Unstructured) (func() error, error) {
kind := managedcluster.GetKind()

if kind != "Deployment" {
return nil, fmt.Errorf("expected kind Deployment, got: %s", kind)
if kind != "ManagedCluster" {
return nil, fmt.Errorf("expected kind ManagedCluster, got: %s", kind)
}

client, err := kc.GetDynamicClient(schema.GroupVersionResource{
Group: "hmc.mirantis.com",
Version: "v1alpha1",
Resource: "deployments",
Resource: "managedclusters",
})
if err != nil {
return nil, fmt.Errorf("failed to get dynamic client: %w", err)
}

_, err = client.Create(ctx, deployment, metav1.CreateOptions{})
_, err = client.Create(ctx, managedcluster, metav1.CreateOptions{})
if err != nil {
return nil, fmt.Errorf("failed to create Deployment: %w", err)
}

return func() error {
err := client.Delete(ctx, deployment.GetName(), metav1.DeleteOptions{})
err := client.Delete(ctx, managedcluster.GetName(), metav1.DeleteOptions{})
if apierrors.IsNotFound(err) {
return nil
}
Expand Down

0 comments on commit 7557577

Please sign in to comment.