Skip to content

Commit

Permalink
Addin runtime controller create.
Browse files Browse the repository at this point in the history
Signed-off-by: muhammad adil ghaffar <[email protected]>
  • Loading branch information
adilGhaffarDev committed Nov 17, 2023
1 parent 3fac15b commit 67b9656
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
2 changes: 1 addition & 1 deletion test/e2e/clusterctl_upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ func ClusterctlUpgradeSpec(ctx context.Context, inputGetter func() ClusterctlUpg
Expect(workloadClusterTemplate).ToNot(BeNil(), "Failed to get the cluster template")

log.Logf("Applying the cluster template yaml to the cluster")
Expect(managementClusterProxy.Apply(ctx, workloadClusterTemplate)).To(Succeed())
Expect(managementClusterProxy.Create(ctx, workloadClusterTemplate)).To(Succeed())

if input.PreWaitForCluster != nil {
By("Running PreWaitForCluster steps against the management cluster")
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/kcp_remediations.go
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ func createWorkloadClusterAndWait(ctx context.Context, input createWorkloadClust
Expect(workloadClusterTemplate).ToNot(BeNil(), "Failed to get the cluster template")

Eventually(func() error {
return input.Proxy.Apply(ctx, workloadClusterTemplate)
return input.Proxy.Create(ctx, workloadClusterTemplate)
}, 10*time.Second).Should(Succeed(), "Failed to apply the cluster template")

log.Logf("Waiting for the cluster infrastructure to be provisioned")
Expand Down
27 changes: 27 additions & 0 deletions test/framework/cluster_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime"
kerrors "k8s.io/apimachinery/pkg/util/errors"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
Expand All @@ -45,6 +47,7 @@ import (
"sigs.k8s.io/cluster-api/test/framework/exec"
"sigs.k8s.io/cluster-api/test/framework/internal/log"
"sigs.k8s.io/cluster-api/test/infrastructure/container"
"sigs.k8s.io/cluster-api/util/yaml"
)

const (
Expand Down Expand Up @@ -90,6 +93,9 @@ type ClusterProxy interface {
// Apply to apply YAML to the Kubernetes cluster, `kubectl apply`.
Apply(ctx context.Context, resources []byte, args ...string) error

// Create creates using the controller-runtime client.
Create(ctx context.Context, resources []byte) error

// GetWorkloadCluster returns a proxy to a workload cluster defined in the Kubernetes cluster.
GetWorkloadCluster(ctx context.Context, namespace, name string) ClusterProxy

Expand Down Expand Up @@ -247,6 +253,27 @@ func (p *clusterProxy) Apply(ctx context.Context, resources []byte, args ...stri
return exec.KubectlApply(ctx, p.kubeconfigPath, resources, args...)
}

// Create creates using the controller-runtime client.
func (p *clusterProxy) Create(ctx context.Context, resources []byte) error {
Expect(ctx).NotTo(BeNil(), "ctx is required for Create")
Expect(resources).NotTo(BeNil(), "resources is required for Create")

var retErrs []error
objs, err := yaml.ToUnstructured(resources)
if err != nil {
return err
}
for o := range objs {
if err := p.GetClient().Create(ctx, &objs[o]); err != nil {
if apierrors.IsAlreadyExists(err) {
continue
}
retErrs = append(retErrs, err)
}
}
return kerrors.NewAggregate(retErrs)
}

func (p *clusterProxy) GetRESTConfig() *rest.Config {
config, err := clientcmd.LoadFromFile(p.kubeconfigPath)
Expect(err).ToNot(HaveOccurred(), "Failed to load Kubeconfig file from %q", p.kubeconfigPath)
Expand Down
2 changes: 1 addition & 1 deletion test/framework/clusterctl/clusterctl_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ func ApplyClusterTemplateAndWait(ctx context.Context, input ApplyClusterTemplate
cniYaml, err := os.ReadFile(input.CNIManifestPath)
Expect(err).ShouldNot(HaveOccurred())

Expect(workloadCluster.Apply(ctx, cniYaml)).ShouldNot(HaveOccurred())
Expect(workloadCluster.Create(ctx, cniYaml)).ShouldNot(HaveOccurred())
}

log.Logf("Waiting for control plane to be ready")
Expand Down

0 comments on commit 67b9656

Please sign in to comment.