Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mitalipaygude committed Jan 23, 2024
1 parent 0145636 commit 47db5fa
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 104 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,EksaInstaller
${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,ClientFactory,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
71 changes: 40 additions & 31 deletions pkg/clustermanager/eksa_installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,26 +59,20 @@ func WithEKSAInstallerNoTimeouts() EKSAInstallerOpt {

// Install configures and applies eks-a components in a cluster accordingly to a spec.
func (i *EKSAInstaller) Install(ctx context.Context, log logr.Logger, cluster *types.Cluster, spec *cluster.Spec) error {
generator := EKSAComponentGenerator{log: log, reader: i.reader}
components, err := generator.buildEKSAComponentsSpec(spec)

err := i.createEKSAComponents(ctx, log, cluster, spec)
if err != nil {
return err
}

objs := make([]runtime.Object, 0, len(components.rest)+1)
objs = append(objs, components.deployment)
for _, o := range components.rest {
objs = append(objs, o)
return fmt.Errorf("applying EKSA components: %v", err)
}

for _, o := range objs {
if err = i.client.Apply(ctx, cluster.KubeconfigFile, o); err != nil {
return fmt.Errorf("applying eksa components: %v", err)
}
err = i.applyBundles(ctx, log, cluster, spec)
if err != nil {
return fmt.Errorf("applying EKSA bundles: %v", err)
}

if err := i.client.WaitForDeployment(ctx, cluster, i.deploymentWaitTimeout.String(), "Available", constants.EksaControllerManagerDeployment, constants.EksaSystemNamespace); err != nil {
return fmt.Errorf("waiting for eksa-controller-manager: %v", err)
err = i.applyReleases(ctx, log, cluster, spec)
if err != nil {
return fmt.Errorf("applying EKSA releases: %v", err)
}

return nil
Expand All @@ -102,15 +96,41 @@ func (i *EKSAInstaller) Upgrade(ctx context.Context, log logr.Logger, c *types.C
newVersionsBundle := newSpec.RootVersionsBundle()
oldVersion := oldVersionsBundle.Eksa.Version
newVersion := newVersionsBundle.Eksa.Version
if err := i.Install(ctx, log, c, newSpec); err != nil {
if err := i.createEKSAComponents(ctx, log, c, newSpec); err != nil {
return nil, fmt.Errorf("upgrading EKS-A components from version %v to version %v: %v", oldVersion, newVersion, err)
}

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 {
// createEKSAComponents creates eksa components and applies the objects to the cluster.
func (i *EKSAInstaller) createEKSAComponents(ctx context.Context, log logr.Logger, cluster *types.Cluster, spec *cluster.Spec) error {
generator := EKSAComponentGenerator{log: log, reader: i.reader}
components, err := generator.buildEKSAComponentsSpec(spec)
if err != nil {
return err
}

objs := make([]runtime.Object, 0, len(components.rest)+1)
objs = append(objs, components.deployment)
for _, o := range components.rest {
objs = append(objs, o)
}

for _, o := range objs {
if err = i.client.Apply(ctx, cluster.KubeconfigFile, o); err != nil {
return fmt.Errorf("applying eksa components: %v", err)
}
}

if err := i.client.WaitForDeployment(ctx, cluster, i.deploymentWaitTimeout.String(), "Available", constants.EksaControllerManagerDeployment, constants.EksaSystemNamespace); err != nil {
return fmt.Errorf("waiting for eksa-controller-manager: %v", err)
}

return 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)
Expand All @@ -124,8 +144,8 @@ func (i *EKSAInstaller) ApplyBundles(ctx context.Context, log logr.Logger, clust
return nil
}

// ApplyReleases applies the releases to the cluster.
func (i *EKSAInstaller) ApplyReleases(ctx context.Context, log logr.Logger, cluster *types.Cluster, spec *cluster.Spec) error {
// 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)
Expand All @@ -139,17 +159,6 @@ func (i *EKSAInstaller) ApplyReleases(ctx context.Context, log logr.Logger, clus
return nil
}

// 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
}
}

return nil
}

// EKSAComponentGenerator generates and configures eks-a components.
type EKSAComponentGenerator struct {
log logr.Logger
Expand Down
11 changes: 8 additions & 3 deletions pkg/workflows/interfaces/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,20 @@ import (
"github.com/go-logr/logr"

"github.com/aws/eks-anywhere/pkg/bootstrapper"
"github.com/aws/eks-anywhere/pkg/clients/kubernetes"
"github.com/aws/eks-anywhere/pkg/cluster"
"github.com/aws/eks-anywhere/pkg/constants"
"github.com/aws/eks-anywhere/pkg/providers"
"github.com/aws/eks-anywhere/pkg/types"
"github.com/aws/eks-anywhere/pkg/validations"
)

// ClientFactory builds Kubernetes clients.
type ClientFactory interface {
// BuildClientFromKubeconfig builds a Kubernetes client from a kubeconfig file.
BuildClientFromKubeconfig(kubeconfigPath string) (kubernetes.Client, error)
}

type Bootstrapper interface {
CreateBootstrapCluster(ctx context.Context, clusterSpec *cluster.Spec, opts ...bootstrapper.BootstrapClusterOption) (*types.Cluster, error)
DeleteBootstrapCluster(context.Context, *types.Cluster, constants.Operation, bool) error
Expand Down Expand Up @@ -97,7 +104,5 @@ type ClusterCreator interface {

// 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
Install(ctx context.Context, log logr.Logger, cluster *types.Cluster, spec *cluster.Spec) error
}
95 changes: 46 additions & 49 deletions pkg/workflows/interfaces/mocks/clients.go

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

23 changes: 3 additions & 20 deletions pkg/workflows/management/create_install_eksa.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,35 +35,18 @@ func (s *installEksaComponentsOnBootstrapTask) Checkpoint() *task.CompletedTask
}

func installEKSAComponents(ctx context.Context, commandContext *task.CommandContext, targetCluster *types.Cluster) error {
logger.Info("Installing EKS-A custom components (CRD and controller)")
err := commandContext.ClusterManager.InstallCustomComponents(ctx, commandContext.ClusterSpec, targetCluster, commandContext.Provider)
if err != nil {
commandContext.SetError(err)
return err
}

logger.Info("Installing EKS-D components")
err = commandContext.EksdInstaller.InstallEksdCRDs(ctx, commandContext.ClusterSpec, targetCluster)
err := commandContext.EksdInstaller.InstallEksdCRDs(ctx, commandContext.ClusterSpec, targetCluster)
if err != nil {
commandContext.SetError(err)
return err
}

logger.Info("Creating EKS-A CRDs instances")

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

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

err = commandContext.EksaInstaller.ApplyReleases(ctx, logger.Get(), targetCluster, commandContext.ClusterSpec)
logger.Info("Installing EKS-A custom components (CRD and controller)")
err = commandContext.ClusterManager.InstallCustomComponents(ctx, commandContext.ClusterSpec, targetCluster, commandContext.Provider)
if err != nil {
commandContext.SetError(err)
return err
Expand Down

0 comments on commit 47db5fa

Please sign in to comment.