Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update kubectl ValidateWorkerNodes arg to pass in kubeconfig #1149

Merged
merged 1 commit into from
Feb 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/eks-a-tool/cmd/validatecluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func validateCluster(ctx context.Context, cluster *types.Cluster, clusterName st
if err != nil {
return err
}
err = kubectl.ValidateWorkerNodes(ctx, cluster, clusterName)
err = kubectl.ValidateWorkerNodes(ctx, clusterName, cluster.KubeconfigFile)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/clustermanager/cluster_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ type ClusterClient interface {
CreateNamespace(ctx context.Context, kubeconfig string, namespace string) error
GetNamespace(ctx context.Context, kubeconfig string, namespace string) error
ValidateControlPlaneNodes(ctx context.Context, cluster *types.Cluster, clusterName string) error
ValidateWorkerNodes(ctx context.Context, cluster *types.Cluster, clusterName string) error
ValidateWorkerNodes(ctx context.Context, clusterName string, kubeconfigFile string) error
GetBundles(ctx context.Context, kubeconfigFile, name, namespace string) (*releasev1alpha1.Bundles, error)
GetApiServerUrl(ctx context.Context, cluster *types.Cluster) (string, error)
GetClusterCATlsCert(ctx context.Context, clusterName string, cluster *types.Cluster, namespace string) ([]byte, error)
Expand Down Expand Up @@ -728,7 +728,7 @@ func (c *ClusterManager) waitForMachineDeploymentReplicasReady(ctx context.Conte
}

isMdReady := func() error {
return c.clusterClient.ValidateWorkerNodes(ctx, managementCluster, clusterSpec.Name)
return c.clusterClient.ValidateWorkerNodes(ctx, clusterSpec.Name, managementCluster.KubeconfigFile)
}

err := isMdReady()
Expand Down
8 changes: 4 additions & 4 deletions pkg/clustermanager/cluster_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ func TestClusterManagerUpgradeWorkloadClusterSuccess(t *testing.T) {
tt.mocks.client.EXPECT().GetMachines(tt.ctx, mCluster, mCluster.Name).Return([]types.Machine{}, nil).Times(2)
tt.mocks.client.EXPECT().WaitForDeployment(tt.ctx, wCluster, "30m", "Available", gomock.Any(), gomock.Any()).MaxTimes(10)
tt.mocks.client.EXPECT().ValidateControlPlaneNodes(tt.ctx, mCluster, wCluster.Name).Return(nil)
tt.mocks.client.EXPECT().ValidateWorkerNodes(tt.ctx, mCluster, wCluster.Name).Return(nil)
tt.mocks.client.EXPECT().ValidateWorkerNodes(tt.ctx, wCluster.Name, mCluster.KubeconfigFile).Return(nil)
tt.mocks.provider.EXPECT().GetDeployments()
tt.mocks.writer.EXPECT().Write(clusterName+"-eks-a-cluster.yaml", gomock.Any(), gomock.Not(gomock.Nil()))

Expand Down Expand Up @@ -577,7 +577,7 @@ func TestClusterManagerUpgradeWorkloadClusterWaitForCAPITimeout(t *testing.T) {
tt.mocks.client.EXPECT().GetMachines(tt.ctx, mCluster, mCluster.Name).Return([]types.Machine{}, nil).Times(2)
tt.mocks.client.EXPECT().WaitForDeployment(tt.ctx, wCluster, "30m", "Available", gomock.Any(), gomock.Any()).Return(errors.New("time out"))
tt.mocks.client.EXPECT().ValidateControlPlaneNodes(tt.ctx, mCluster, wCluster.Name).Return(nil)
tt.mocks.client.EXPECT().ValidateWorkerNodes(tt.ctx, mCluster, wCluster.Name).Return(nil)
tt.mocks.client.EXPECT().ValidateWorkerNodes(tt.ctx, wCluster.Name, mCluster.KubeconfigFile).Return(nil)
tt.mocks.writer.EXPECT().Write(clusterName+"-eks-a-cluster.yaml", gomock.Any(), gomock.Not(gomock.Nil()))

if err := tt.clusterManager.UpgradeCluster(tt.ctx, mCluster, wCluster, tt.clusterSpec, tt.mocks.provider); err == nil {
Expand Down Expand Up @@ -607,7 +607,7 @@ func TestClusterManagerMoveCAPISuccess(t *testing.T) {
m.client.EXPECT().GetClusters(ctx, to).Return(clusters, nil)
m.client.EXPECT().WaitForControlPlaneReady(ctx, to, "15m0s", capiClusterName)
m.client.EXPECT().ValidateControlPlaneNodes(ctx, to, to.Name)
m.client.EXPECT().ValidateWorkerNodes(ctx, to, to.Name)
m.client.EXPECT().ValidateWorkerNodes(ctx, to.Name, to.KubeconfigFile)
m.client.EXPECT().GetMachines(ctx, to, to.Name)

if err := c.MoveCAPI(ctx, from, to, to.Name, clusterSpec); err != nil {
Expand Down Expand Up @@ -708,7 +708,7 @@ func TestClusterManagerMoveCAPIErrorGetMachines(t *testing.T) {
m.client.EXPECT().MoveManagement(ctx, from, to)
m.client.EXPECT().GetClusters(ctx, to)
m.client.EXPECT().ValidateControlPlaneNodes(ctx, to, to.Name)
m.client.EXPECT().ValidateWorkerNodes(ctx, to, to.Name)
m.client.EXPECT().ValidateWorkerNodes(ctx, to.Name, to.KubeconfigFile)
m.client.EXPECT().GetMachines(ctx, to, from.Name).Return(nil, errors.New("error getting machines")).AnyTimes()

if err := c.MoveCAPI(ctx, from, to, from.Name, clusterSpec); err == nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/clustermanager/mocks/client_and_networking.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pkg/executables/kubectl.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,9 +344,9 @@ func (k *Kubectl) ValidateControlPlaneNodes(ctx context.Context, cluster *types.
return nil
}

func (k *Kubectl) ValidateWorkerNodes(ctx context.Context, cluster *types.Cluster, clusterName string) error {
func (k *Kubectl) ValidateWorkerNodes(ctx context.Context, clusterName string, kubeconfig string) error {
logger.V(6).Info("waiting for nodes", "cluster", clusterName)
deployments, err := k.GetMachineDeployments(ctx, WithCluster(cluster), WithNamespace(constants.EksaSystemNamespace))
deployments, err := k.GetMachineDeployments(ctx, WithKubeconfig(kubeconfig), WithNamespace(constants.EksaSystemNamespace))
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/validations/kubectl.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

type KubectlClient interface {
ValidateControlPlaneNodes(ctx context.Context, cluster *types.Cluster, clusterName string) error
ValidateWorkerNodes(ctx context.Context, cluster *types.Cluster, clusterName string) error
ValidateWorkerNodes(ctx context.Context, clusterName string, kubeconfig string) error
ValidateNodes(ctx context.Context, kubeconfig string) error
ValidateClustersCRD(ctx context.Context, cluster *types.Cluster) error
ValidateEKSAClustersCRD(ctx context.Context, cluster *types.Cluster) error
Expand Down
8 changes: 4 additions & 4 deletions pkg/validations/mocks/kubectl.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/validations/upgradevalidations/preflightvalidations.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (u *UpgradeValidations) PreflightValidations(ctx context.Context) (err erro
validations.ValidationResult{
Name: "worker nodes ready",
Remediation: fmt.Sprintf("ensure machine deployments for cluster %s are Ready", u.Opts.WorkloadCluster.Name),
Err: k.ValidateWorkerNodes(ctx, targetCluster, u.Opts.Spec.Name),
Err: k.ValidateWorkerNodes(ctx, u.Opts.Spec.Name, targetCluster.KubeconfigFile),
},
validations.ValidationResult{
Name: "nodes ready",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ func TestPreflightValidations(t *testing.T) {
provider.EXPECT().ValidateNewSpec(ctx, workloadCluster, clusterSpec).Return(nil).MaxTimes(1)
k.EXPECT().GetEksaVSphereDatacenterConfig(ctx, clusterSpec.Spec.DatacenterRef.Name, gomock.Any(), gomock.Any()).Return(existingProviderSpec, nil).MaxTimes(1)
k.EXPECT().ValidateControlPlaneNodes(ctx, workloadCluster, clusterSpec.Name).Return(tc.cpResponse)
k.EXPECT().ValidateWorkerNodes(ctx, workloadCluster, workloadCluster.Name).Return(tc.workerResponse)
k.EXPECT().ValidateWorkerNodes(ctx, workloadCluster.Name, workloadCluster.KubeconfigFile).Return(tc.workerResponse)
k.EXPECT().ValidateNodes(ctx, kubeconfigFilePath).Return(tc.nodeResponse)
k.EXPECT().ValidateClustersCRD(ctx, workloadCluster).Return(tc.crdResponse)
k.EXPECT().GetClusters(ctx, workloadCluster).Return(tc.getClusterResponse, nil)
Expand Down
2 changes: 1 addition & 1 deletion test/framework/flux.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ func (e *ClusterE2ETest) waitForWorkerNodeValidation() error {
ctx := context.Background()
return retrier.Retry(10, time.Second*10, func() error {
e.T.Log("Attempting to validate worker nodes...")
if err := e.KubectlClient.ValidateWorkerNodes(ctx, e.cluster(), e.ClusterConfig.Name); err != nil {
if err := e.KubectlClient.ValidateWorkerNodes(ctx, e.ClusterConfig.Name, e.cluster().KubeconfigFile); err != nil {
e.T.Logf("Worker node validation failed: %v", err)
return fmt.Errorf("error while validating worker nodes: %v", err)
}
Expand Down