diff --git a/extensions/aws/kubernetes.go b/extensions/aws/kubernetes.go index 1aeee696..c2e4c9a1 100644 --- a/extensions/aws/kubernetes.go +++ b/extensions/aws/kubernetes.go @@ -21,7 +21,7 @@ import ( ) // CreateEKSKubeconfig -func CreateEKSKubeconfig(awsConfig *aws.Config, clusterName string) *k8s.KubernetesClient { +func CreateEKSKubeconfig(awsConfig *aws.Config, clusterName string) (*k8s.KubernetesClient, error) { eksSvc := eks.NewFromConfig(*awsConfig) clusterInput := &eks.DescribeClusterInput{ @@ -30,19 +30,19 @@ func CreateEKSKubeconfig(awsConfig *aws.Config, clusterName string) *k8s.Kuberne eksClusterInfo, err := eksSvc.DescribeCluster(context.Background(), clusterInput) if err != nil { - return &k8s.KubernetesClient{} + return nil, fmt.Errorf("error describing cluster: %w", err) } clientset, restConfig, err := newEKSConfig(eksClusterInfo.Cluster) if err != nil { - return &k8s.KubernetesClient{} + return nil, fmt.Errorf("error creating EKS config: %w", err) } return &k8s.KubernetesClient{ Clientset: clientset, RestConfig: restConfig, KubeConfigPath: "", - } + }, nil } // newEKSConfig diff --git a/internal/controller/argocd.go b/internal/controller/argocd.go index 5d05af99..3666864b 100644 --- a/internal/controller/argocd.go +++ b/internal/controller/argocd.go @@ -35,7 +35,10 @@ func (clctrl *ClusterController) InstallArgoCD() error { switch clctrl.CloudProvider { case "aws": - kcfg = awsext.CreateEKSKubeconfig(&clctrl.AwsClient.Config, clctrl.ClusterName) + kcfg, err = awsext.CreateEKSKubeconfig(&clctrl.AwsClient.Config, clctrl.ClusterName) + if err != nil { + return fmt.Errorf("failed to create eks config: %w", err) + } case "akamai", "civo", "digitalocean", "k3s", "vultr": kcfg, err = k8s.CreateKubeConfig(false, clctrl.ProviderConfig.Kubeconfig) if err != nil { @@ -90,7 +93,10 @@ func (clctrl *ClusterController) InitializeArgoCD() error { switch clctrl.CloudProvider { case "aws": - kcfg = awsext.CreateEKSKubeconfig(&clctrl.AwsClient.Config, clctrl.ClusterName) + kcfg, err = awsext.CreateEKSKubeconfig(&clctrl.AwsClient.Config, clctrl.ClusterName) + if err != nil { + return fmt.Errorf("failed to create eks config: %w", err) + } case "akamai", "civo", "digitalocean", "k3s", "vultr": kcfg, err = k8s.CreateKubeConfig(false, clctrl.ProviderConfig.Kubeconfig) if err != nil { @@ -189,7 +195,10 @@ func (clctrl *ClusterController) DeployRegistryApplication() error { switch clctrl.CloudProvider { case "aws": - kcfg = awsext.CreateEKSKubeconfig(&clctrl.AwsClient.Config, clctrl.ClusterName) + kcfg, err = awsext.CreateEKSKubeconfig(&clctrl.AwsClient.Config, clctrl.ClusterName) + if err != nil { + return fmt.Errorf("failed to create eks config: %w", err) + } case "akamai", "civo", "digitalocean", "k3s", "vultr": kcfg, err = k8s.CreateKubeConfig(false, clctrl.ProviderConfig.Kubeconfig) if err != nil { diff --git a/internal/controller/cluster.go b/internal/controller/cluster.go index 0de64ff4..05bb5871 100644 --- a/internal/controller/cluster.go +++ b/internal/controller/cluster.go @@ -294,7 +294,10 @@ func (clctrl *ClusterController) ClusterSecretsBootstrap() error { switch clctrl.CloudProvider { case "aws": - kcfg = awsext.CreateEKSKubeconfig(&clctrl.AwsClient.Config, clctrl.ClusterName) + kcfg, err = awsext.CreateEKSKubeconfig(&clctrl.AwsClient.Config, clctrl.ClusterName) + if err != nil { + return fmt.Errorf("failed to create eks config: %w", err) + } case "akamai", "civo", "digitalocean", "k3s", "vultr": kcfg, err = k8s.CreateKubeConfig(false, clctrl.ProviderConfig.Kubeconfig) if err != nil { @@ -393,7 +396,11 @@ func (clctrl *ClusterController) ContainerRegistryAuth() (string, error) { switch clctrl.CloudProvider { case "aws": - kcfg = awsext.CreateEKSKubeconfig(&clctrl.AwsClient.Config, clctrl.ClusterName) + var err error + kcfg, err = awsext.CreateEKSKubeconfig(&clctrl.AwsClient.Config, clctrl.ClusterName) + if err != nil { + return "", fmt.Errorf("failed to create eks config: %w", err) + } // Container registry authentication creation containerRegistryAuth := gitShim.ContainerRegistryAuth{ @@ -451,7 +458,11 @@ func (clctrl *ClusterController) WaitForClusterReady() error { switch clctrl.CloudProvider { case "aws": - kcfg = awsext.CreateEKSKubeconfig(&clctrl.AwsClient.Config, clctrl.ClusterName) + var err error + kcfg, err = awsext.CreateEKSKubeconfig(&clctrl.AwsClient.Config, clctrl.ClusterName) + if err != nil { + return fmt.Errorf("failed to create eks config: %w", err) + } case "civo", "digitalocean", "vultr", "k3s": var err error kcfg, err = k8s.CreateKubeConfig(false, clctrl.ProviderConfig.Kubeconfig) diff --git a/internal/controller/kubefirst.go b/internal/controller/kubefirst.go index 06d055d5..88e07bac 100644 --- a/internal/controller/kubefirst.go +++ b/internal/controller/kubefirst.go @@ -68,7 +68,10 @@ func (clctrl *ClusterController) ExportClusterRecord() error { switch clctrl.CloudProvider { case "aws": - kcfg = awsext.CreateEKSKubeconfig(&clctrl.AwsClient.Config, clctrl.ClusterName) + kcfg, err = awsext.CreateEKSKubeconfig(&clctrl.AwsClient.Config, clctrl.ClusterName) + if err != nil { + return fmt.Errorf("failed to create eks config: %w", err) + } case "akamai", "civo", "digitalocean", "k3s", "vultr": kcfg, err = k8s.CreateKubeConfig(false, clctrl.ProviderConfig.Kubeconfig) if err != nil { diff --git a/internal/controller/users.go b/internal/controller/users.go index 903d4cee..d979c9e9 100644 --- a/internal/controller/users.go +++ b/internal/controller/users.go @@ -36,7 +36,10 @@ func (clctrl *ClusterController) RunUsersTerraform() error { switch clctrl.CloudProvider { case "aws": - kcfg = awsext.CreateEKSKubeconfig(&clctrl.AwsClient.Config, clctrl.ClusterName) + kcfg, err = awsext.CreateEKSKubeconfig(&clctrl.AwsClient.Config, clctrl.ClusterName) + if err != nil { + return fmt.Errorf("failed to create eks config: %w", err) + } case "akamai", "civo", "digitalocean", "k3s", "vultr": kcfg, err = k8s.CreateKubeConfig(false, clctrl.ProviderConfig.Kubeconfig) if err != nil { diff --git a/internal/controller/vault.go b/internal/controller/vault.go index 8d8c0910..afddc3be 100644 --- a/internal/controller/vault.go +++ b/internal/controller/vault.go @@ -71,7 +71,10 @@ func (clctrl *ClusterController) InitializeVault() error { switch clctrl.CloudProvider { case "aws": - kcfg = awsext.CreateEKSKubeconfig(&clctrl.AwsClient.Config, clctrl.ClusterName) + kcfg, err = awsext.CreateEKSKubeconfig(&clctrl.AwsClient.Config, clctrl.ClusterName) + if err != nil { + return fmt.Errorf("failed to create eks config: %w", err) + } case "akamai", "civo", "digitalocean", "k3s", "vultr": kcfg, err = k8s.CreateKubeConfig(false, clctrl.ProviderConfig.Kubeconfig) if err != nil { @@ -168,7 +171,10 @@ func (clctrl *ClusterController) RunVaultTerraform() error { switch clctrl.CloudProvider { case "aws": - kcfg = awsext.CreateEKSKubeconfig(&clctrl.AwsClient.Config, clctrl.ClusterName) + kcfg, err = awsext.CreateEKSKubeconfig(&clctrl.AwsClient.Config, clctrl.ClusterName) + if err != nil { + return fmt.Errorf("failed to create eks config: %w", err) + } case "akamai", "civo", "digitalocean", "k3s", "vultr": kcfg, err = k8s.CreateKubeConfig(false, clctrl.ProviderConfig.Kubeconfig) if err != nil { @@ -301,7 +307,10 @@ func (clctrl *ClusterController) WriteVaultSecrets() error { var kcfg *k8s.KubernetesClient switch clctrl.CloudProvider { case "aws": - kcfg = awsext.CreateEKSKubeconfig(&clctrl.AwsClient.Config, clctrl.ClusterName) + kcfg, err = awsext.CreateEKSKubeconfig(&clctrl.AwsClient.Config, clctrl.ClusterName) + if err != nil { + return fmt.Errorf("failed to create eks config: %w", err) + } case "akamai", "civo", "digitalocean", "k3s", "vultr": kcfg, err = k8s.CreateKubeConfig(false, clctrl.ProviderConfig.Kubeconfig) if err != nil { @@ -385,7 +394,11 @@ func (clctrl *ClusterController) WaitForVault() error { switch clctrl.CloudProvider { case "aws": - kcfg = awsext.CreateEKSKubeconfig(&clctrl.AwsClient.Config, clctrl.ClusterName) + var err error + kcfg, err = awsext.CreateEKSKubeconfig(&clctrl.AwsClient.Config, clctrl.ClusterName) + if err != nil { + return fmt.Errorf("failed to create eks config: %w", err) + } case "akamai", "civo", "digitalocean", "k3s", "vultr": var err error kcfg, err = k8s.CreateKubeConfig(false, clctrl.ProviderConfig.Kubeconfig) diff --git a/providers/aws/create.go b/providers/aws/create.go index 49b531b7..90516d7c 100644 --- a/providers/aws/create.go +++ b/providers/aws/create.go @@ -106,7 +106,10 @@ func CreateAWSCluster(definition *pkgtypes.ClusterDefinition) error { // Get Cluster kubeconfig and save to path so we can reference like everything else // TODO replace constant references to a new config with references to an existing config created here // for all cloud providers - ctrl.Kcfg = awsext.CreateEKSKubeconfig(&ctrl.AwsClient.Config, ctrl.ClusterName) + ctrl.Kcfg, err = awsext.CreateEKSKubeconfig(&ctrl.AwsClient.Config, ctrl.ClusterName) + if err != nil { + return fmt.Errorf("failed to create eks config: %w", err) + } if err := ctrl.WaitForClusterReady(); err != nil { ctrl.UpdateClusterOnError(err.Error()) return fmt.Errorf("error waiting for cluster to be ready: %w", err) diff --git a/providers/aws/delete.go b/providers/aws/delete.go index a5ce987c..e620b847 100644 --- a/providers/aws/delete.go +++ b/providers/aws/delete.go @@ -154,8 +154,10 @@ func DeleteAWSCluster(cl *pkgtypes.Cluster, telemetryEvent telemetry.TelemetryEv awsClient := &awsinternal.Configuration{ Config: conf, } - kcfg := awsext.CreateEKSKubeconfig(&awsClient.Config, cl.ClusterName) - + kcfg, err := awsext.CreateEKSKubeconfig(&awsClient.Config, cl.ClusterName) + if err != nil { + return fmt.Errorf("failed to create eks config: %w", err) + } log.Info().Msg("destroying aws resources with terraform") // Only port-forward to ArgoCD and delete registry if ArgoCD was installed