Skip to content

Commit

Permalink
Use Eksa installer
Browse files Browse the repository at this point in the history
  • Loading branch information
mitalipaygude committed Jan 18, 2024
1 parent bbb7d5d commit 0145636
Show file tree
Hide file tree
Showing 12 changed files with 250 additions and 82 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ mocks: ## Generate mocks
${MOCKGEN} -destination=pkg/bootstrapper/mocks/bootstrapper.go -package=mocks "github.com/aws/eks-anywhere/pkg/bootstrapper" ClusterClient
${MOCKGEN} -destination=pkg/git/providers/github/mocks/github.go -package=mocks "github.com/aws/eks-anywhere/pkg/git/providers/github" GithubClient
${MOCKGEN} -destination=pkg/git/mocks/git.go -package=mocks "github.com/aws/eks-anywhere/pkg/git" Client,ProviderClient
${MOCKGEN} -destination=pkg/workflows/interfaces/mocks/clients.go -package=mocks "github.com/aws/eks-anywhere/pkg/workflows/interfaces" Bootstrapper,ClusterManager,GitOpsManager,Validator,CAPIManager,EksdInstaller,EksdUpgrader,PackageInstaller,ClusterUpgrader,ClusterCreator
${MOCKGEN} -destination=pkg/workflows/interfaces/mocks/clients.go -package=mocks "github.com/aws/eks-anywhere/pkg/workflows/interfaces" Bootstrapper,ClusterManager,GitOpsManager,Validator,CAPIManager,EksdInstaller,EksdUpgrader,PackageInstaller,ClusterUpgrader,ClusterCreator,EksaInstaller
${MOCKGEN} -destination=pkg/git/gogithub/mocks/client.go -package=mocks "github.com/aws/eks-anywhere/pkg/git/gogithub" Client
${MOCKGEN} -destination=pkg/git/gitclient/mocks/client.go -package=mocks "github.com/aws/eks-anywhere/pkg/git/gitclient" GoGit
${MOCKGEN} -destination=pkg/validations/mocks/docker.go -package=mocks "github.com/aws/eks-anywhere/pkg/validations" DockerExecutable
Expand Down
1 change: 1 addition & 0 deletions pkg/clustermanager/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type KubernetesClient interface {
WaitForDeployment(ctx context.Context, cluster *types.Cluster, timeout string, condition string, target string, namespace string) error
UpdateAnnotationInNamespace(ctx context.Context, resourceType, objectName string, annotations map[string]string, cluster *types.Cluster, namespace string) error
RemoveAnnotationInNamespace(ctx context.Context, resourceType, objectName, key string, cluster *types.Cluster, namespace string) error
CreateNamespaceIfNotPresent(ctx context.Context, kubeconfig string, namespace string) error
}

type clusterManagerClient struct {
Expand Down
16 changes: 0 additions & 16 deletions pkg/clustermanager/cluster_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -523,22 +523,6 @@ func (c *ClusterManager) getWorkloadClusterKubeconfig(ctx context.Context, clust
return nil
}

// CreateEKSAReleaseBundle applies the eks-a release bundle to the cluster.
func (c *ClusterManager) CreateEKSAReleaseBundle(ctx context.Context, cluster *types.Cluster, clusterSpec *cluster.Spec) error {
if clusterSpec.Cluster.Namespace != "" {
if err := c.clusterClient.CreateNamespaceIfNotPresent(ctx, cluster.KubeconfigFile, clusterSpec.Cluster.Namespace); err != nil {
return err
}
}

clusterSpec.Cluster.AddManagedByCLIAnnotation()

if err := c.ApplyBundles(ctx, clusterSpec, cluster); err != nil {
return err
}
return c.ApplyReleases(ctx, clusterSpec, cluster)
}

func (c *ClusterManager) RunPostCreateWorkloadCluster(ctx context.Context, managementCluster, workloadCluster *types.Cluster, clusterSpec *cluster.Spec) error {
logger.V(3).Info("Waiting for controlplane and worker machines to be ready")
labels := []string{clusterv1.MachineControlPlaneNameLabel, clusterv1.MachineDeploymentNameLabel}
Expand Down
42 changes: 42 additions & 0 deletions pkg/clustermanager/eksa_installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
"sigs.k8s.io/yaml"

anywherev1 "github.com/aws/eks-anywhere/pkg/api/v1alpha1"
"github.com/aws/eks-anywhere/pkg/cluster"
Expand Down Expand Up @@ -108,6 +109,47 @@ func (i *EKSAInstaller) Upgrade(ctx context.Context, log logr.Logger, c *types.C
return changeDiff, nil
}

// ApplyBundles applies the bundles to the cluster.
func (i *EKSAInstaller) ApplyBundles(ctx context.Context, log logr.Logger, cluster *types.Cluster, spec *cluster.Spec) error {
bundleObj, err := yaml.Marshal(spec.Bundles)
if err != nil {
return fmt.Errorf("outputting bundle yaml: %v", err)
}

Check warning on line 117 in pkg/clustermanager/eksa_installer.go

View check run for this annotation

Codecov / codecov/patch

pkg/clustermanager/eksa_installer.go#L113-L117

Added lines #L113 - L117 were not covered by tests

log.V(1).Info("Applying Bundles to cluster")
if err := i.client.ApplyKubeSpecFromBytes(ctx, cluster, bundleObj); err != nil {
return fmt.Errorf("applying bundle spec: %v", err)
}

Check warning on line 122 in pkg/clustermanager/eksa_installer.go

View check run for this annotation

Codecov / codecov/patch

pkg/clustermanager/eksa_installer.go#L119-L122

Added lines #L119 - L122 were not covered by tests

return nil

Check warning on line 124 in pkg/clustermanager/eksa_installer.go

View check run for this annotation

Codecov / codecov/patch

pkg/clustermanager/eksa_installer.go#L124

Added line #L124 was not covered by tests
}

// ApplyReleases applies the releases to the cluster.
func (i *EKSAInstaller) ApplyReleases(ctx context.Context, log logr.Logger, cluster *types.Cluster, spec *cluster.Spec) error {
releaseObj, err := yaml.Marshal(spec.EKSARelease)
if err != nil {
return fmt.Errorf("outputting release yaml: %v", err)
}

Check warning on line 132 in pkg/clustermanager/eksa_installer.go

View check run for this annotation

Codecov / codecov/patch

pkg/clustermanager/eksa_installer.go#L128-L132

Added lines #L128 - L132 were not covered by tests

log.V(1).Info("Applying EKSA Release to cluster")
if err := i.client.ApplyKubeSpecFromBytes(ctx, cluster, releaseObj); err != nil {
return fmt.Errorf("applying release spec: %v", err)
}

Check warning on line 137 in pkg/clustermanager/eksa_installer.go

View check run for this annotation

Codecov / codecov/patch

pkg/clustermanager/eksa_installer.go#L134-L137

Added lines #L134 - L137 were not covered by tests

return nil

Check warning on line 139 in pkg/clustermanager/eksa_installer.go

View check run for this annotation

Codecov / codecov/patch

pkg/clustermanager/eksa_installer.go#L139

Added line #L139 was not covered by tests
}

// CreateNamespaceIfNotPresent creates the cluster namespace if it doesn not exist.
func (i *EKSAInstaller) CreateNamespaceIfNotPresent(ctx context.Context, log logr.Logger, cluster *types.Cluster, spec *cluster.Spec) error {
if spec.Cluster.Namespace != "" {
if err := i.client.CreateNamespaceIfNotPresent(ctx, cluster.KubeconfigFile, spec.Cluster.Namespace); err != nil {
return err
}

Check warning on line 147 in pkg/clustermanager/eksa_installer.go

View check run for this annotation

Codecov / codecov/patch

pkg/clustermanager/eksa_installer.go#L143-L147

Added lines #L143 - L147 were not covered by tests
}

return nil

Check warning on line 150 in pkg/clustermanager/eksa_installer.go

View check run for this annotation

Codecov / codecov/patch

pkg/clustermanager/eksa_installer.go#L150

Added line #L150 was not covered by tests
}

// EKSAComponentGenerator generates and configures eks-a components.
type EKSAComponentGenerator struct {
log logr.Logger
Expand Down
14 changes: 14 additions & 0 deletions pkg/clustermanager/mocks/client_and_networking.go

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

34 changes: 34 additions & 0 deletions pkg/dependencies/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ type Dependencies struct {
CiliumTemplater *cilium.Templater
AwsIamAuth *awsiamauth.Installer
ClusterManager *clustermanager.ClusterManager
EksaInstaller *clustermanager.EKSAInstaller
Bootstrapper *bootstrapper.Bootstrapper
GitOpsFlux *flux.Flux
Git *gitfactory.GitTools
Expand Down Expand Up @@ -1103,6 +1104,39 @@ func (f *Factory) WithClusterManager(clusterConfig *v1alpha1.Cluster, timeoutOpt
return f
}

// WithEKSAInstaller builds a cluster manager based on the cluster config and timeout options.
func (f *Factory) WithEKSAInstaller(clusterConfig *v1alpha1.Cluster, timeoutOpts *ClusterManagerTimeoutOptions) *Factory {
f.WithClusterctl().WithKubectl().WithFileReader()

f.buildSteps = append(f.buildSteps, func(ctx context.Context) error {
if f.dependencies.EksaInstaller != nil {
return nil
}

Check warning on line 1114 in pkg/dependencies/factory.go

View check run for this annotation

Codecov / codecov/patch

pkg/dependencies/factory.go#L1108-L1114

Added lines #L1108 - L1114 were not covered by tests

var r *retrier.Retrier
if f.config.noTimeouts {
r = retrier.NewWithNoTimeout()
} else {
r = clustermanager.DefaultRetrier()
}

Check warning on line 1121 in pkg/dependencies/factory.go

View check run for this annotation

Codecov / codecov/patch

pkg/dependencies/factory.go#L1116-L1121

Added lines #L1116 - L1121 were not covered by tests

client := clustermanager.NewRetrierClient(
&clusterManagerClient{
f.dependencies.Clusterctl,
f.dependencies.Kubectl,
},
r,
)

installer := clustermanager.NewEKSAInstaller(client, f.dependencies.FileReader, f.eksaInstallerOpts()...)

f.dependencies.EksaInstaller = installer
return nil

Check warning on line 1134 in pkg/dependencies/factory.go

View check run for this annotation

Codecov / codecov/patch

pkg/dependencies/factory.go#L1123-L1134

Added lines #L1123 - L1134 were not covered by tests
})

return f

Check warning on line 1137 in pkg/dependencies/factory.go

View check run for this annotation

Codecov / codecov/patch

pkg/dependencies/factory.go#L1137

Added line #L1137 was not covered by tests
}

// WithNoTimeouts injects no timeouts to all the dependencies with configurable timeout.
// Calling this method sets no timeout for the waits and retries in all the
// cluster operations, i.e. cluster manager, eksa installer, networking installer.
Expand Down
1 change: 1 addition & 0 deletions pkg/task/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type CommandContext struct {
EksdInstaller interfaces.EksdInstaller
PackageInstaller interfaces.PackageInstaller
EksdUpgrader interfaces.EksdUpgrader
EksaInstaller interfaces.EksaInstaller
ClusterUpgrader interfaces.ClusterUpgrader
ClusterCreator interfaces.ClusterCreator
CAPIManager interfaces.CAPIManager
Expand Down
10 changes: 9 additions & 1 deletion pkg/workflows/interfaces/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package interfaces
import (
"context"

"github.com/go-logr/logr"

"github.com/aws/eks-anywhere/pkg/bootstrapper"
"github.com/aws/eks-anywhere/pkg/cluster"
"github.com/aws/eks-anywhere/pkg/constants"
Expand Down Expand Up @@ -32,7 +34,6 @@ type ClusterManager interface {
SaveLogsManagementCluster(ctx context.Context, spec *cluster.Spec, cluster *types.Cluster) error
SaveLogsWorkloadCluster(ctx context.Context, provider providers.Provider, spec *cluster.Spec, cluster *types.Cluster) error
InstallCustomComponents(ctx context.Context, clusterSpec *cluster.Spec, cluster *types.Cluster, provider providers.Provider) error
CreateEKSAReleaseBundle(ctx context.Context, cluster *types.Cluster, clusterSpec *cluster.Spec) error
CreateEKSANamespace(ctx context.Context, cluster *types.Cluster) error
CreateEKSAResources(ctx context.Context, cluster *types.Cluster, clusterSpec *cluster.Spec, datacenterConfig providers.DatacenterConfig, machineConfigs []providers.MachineConfig) error
ApplyBundles(ctx context.Context, clusterSpec *cluster.Spec, cluster *types.Cluster) error
Expand Down Expand Up @@ -93,3 +94,10 @@ type ClusterCreator interface {
Run(ctx context.Context, spec *cluster.Spec, managementCluster types.Cluster) error
CreateSync(ctx context.Context, spec *cluster.Spec, managementCluster *types.Cluster) (*types.Cluster, error)
}

// EksaInstaller exposes the EKSA installer methods.
type EksaInstaller interface {
ApplyBundles(ctx context.Context, log logr.Logger, cluster *types.Cluster, spec *cluster.Spec) error
ApplyReleases(ctx context.Context, log logr.Logger, cluster *types.Cluster, spec *cluster.Spec) error
CreateNamespaceIfNotPresent(ctx context.Context, log logr.Logger, cluster *types.Cluster, spec *cluster.Spec) error
}
68 changes: 67 additions & 1 deletion pkg/workflows/interfaces/mocks/clients.go

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

5 changes: 4 additions & 1 deletion pkg/workflows/management/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@ type Create struct {
eksdInstaller interfaces.EksdInstaller
packageInstaller interfaces.PackageInstaller
clusterCreator interfaces.ClusterCreator
eksaInstaller interfaces.EksaInstaller
}

// NewCreate builds a new create construct.
func NewCreate(bootstrapper interfaces.Bootstrapper, provider providers.Provider,
clusterManager interfaces.ClusterManager, gitOpsManager interfaces.GitOpsManager,
writer filewriter.FileWriter, eksdInstaller interfaces.EksdInstaller,
packageInstaller interfaces.PackageInstaller,
clusterCreator interfaces.ClusterCreator,
clusterCreator interfaces.ClusterCreator, eksaInstaller interfaces.EksaInstaller,
) *Create {
return &Create{
bootstrapper: bootstrapper,
Expand All @@ -38,6 +39,7 @@ func NewCreate(bootstrapper interfaces.Bootstrapper, provider providers.Provider
eksdInstaller: eksdInstaller,
packageInstaller: packageInstaller,
clusterCreator: clusterCreator,
eksaInstaller: eksaInstaller,
}
}

Expand All @@ -54,6 +56,7 @@ func (c *Create) Run(ctx context.Context, clusterSpec *cluster.Spec, validator i
EksdInstaller: c.eksdInstaller,
PackageInstaller: c.packageInstaller,
ClusterCreator: c.clusterCreator,
EksaInstaller: c.eksaInstaller,
}

return task.NewTaskRunner(&setupAndValidateCreate{}, c.writer).RunTask(ctx, commandContext)
Expand Down
15 changes: 14 additions & 1 deletion pkg/workflows/management/create_install_eksa.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,20 @@ func installEKSAComponents(ctx context.Context, commandContext *task.CommandCont
}

logger.Info("Creating EKS-A CRDs instances")
err = commandContext.ClusterManager.CreateEKSAReleaseBundle(ctx, targetCluster, commandContext.ClusterSpec)

err = commandContext.EksaInstaller.CreateNamespaceIfNotPresent(ctx, logger.Get(), targetCluster, commandContext.ClusterSpec)
if err != nil {
commandContext.SetError(err)
return err
}

Check warning on line 58 in pkg/workflows/management/create_install_eksa.go

View check run for this annotation

Codecov / codecov/patch

pkg/workflows/management/create_install_eksa.go#L52-L58

Added lines #L52 - L58 were not covered by tests

err = commandContext.EksaInstaller.ApplyBundles(ctx, logger.Get(), targetCluster, commandContext.ClusterSpec)
if err != nil {
commandContext.SetError(err)
return err
}

Check warning on line 64 in pkg/workflows/management/create_install_eksa.go

View check run for this annotation

Codecov / codecov/patch

pkg/workflows/management/create_install_eksa.go#L60-L64

Added lines #L60 - L64 were not covered by tests

err = commandContext.EksaInstaller.ApplyReleases(ctx, logger.Get(), targetCluster, commandContext.ClusterSpec)
if err != nil {
commandContext.SetError(err)
return err
Expand Down
Loading

0 comments on commit 0145636

Please sign in to comment.