Skip to content

Commit

Permalink
POC with applier
Browse files Browse the repository at this point in the history
  • Loading branch information
mitalipaygude committed Nov 21, 2023
1 parent 9443f91 commit 9cb8c74
Show file tree
Hide file tree
Showing 9 changed files with 270 additions and 174 deletions.
16 changes: 11 additions & 5 deletions cmd/eksctl-anywhere/cmd/createcluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"errors"
"fmt"
"strings"
"os"

"github.com/spf13/cobra"
"github.com/spf13/pflag"
Expand All @@ -24,6 +23,7 @@ import (
"github.com/aws/eks-anywhere/pkg/validations/createvalidations"
"github.com/aws/eks-anywhere/pkg/workflow/management"
"github.com/aws/eks-anywhere/pkg/workflows"
"github.com/aws/eks-anywhere/pkg/workflows/workload"
)

type createClusterOptions struct {
Expand Down Expand Up @@ -193,7 +193,8 @@ func (cc *createClusterOptions) createCluster(cmd *cobra.Command, _ []string) er
WithEksdInstaller().
WithPackageInstaller(clusterSpec, cc.installPackages, cc.managementKubeconfig).
WithValidatorClients().
WithCreateClusterDefaulter(createCLIConfig)
WithCreateClusterDefaulter(createCLIConfig).
WithClusterApplier()

if cc.timeoutOptions.noTimeouts {
factory.WithNoTimeouts()
Expand Down Expand Up @@ -261,16 +262,21 @@ func (cc *createClusterOptions) createCluster(cmd *cobra.Command, _ []string) er
err = wflw.Run(ctx)
} else if features.UseControllerViaCLIWorkflow().IsActive() && clusterConfig.IsManaged() {

eksaSpec, _ := os.ReadFile(cc.fileName)
// eksaSpec, _ := os.ReadFile(cc.fileName)
logger.Info("-----------------------------------------------------")

logger.Info("POC Inside controller via CLI workflow")

createWorkloadCluster := workflows.NewCreateWorkload(
createWorkloadCluster := workload.NewCreateWorkload(
deps.Provider,
deps.ClusterManager,
deps.GitOpsFlux,
deps.Writer,
deps.ClusterApplier,
deps.EksdInstaller,
deps.PackageInstaller,
)
err = createWorkloadCluster.Run(ctx, clusterSpec, createValidations, eksaSpec)
err = createWorkloadCluster.Run(ctx, clusterSpec, createValidations)

} else {
err = createCluster.Run(ctx, clusterSpec, createValidations, cc.forceClean)
Expand Down
4 changes: 3 additions & 1 deletion pkg/cluster/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,9 @@ func (b FileSpecBuilder) Build(clusterConfigURL string) (*Spec, error) {
}

releaseVersion := v1alpha1.EksaVersion(release.Version)
config.Cluster.Spec.EksaVersion = &releaseVersion
if config.Cluster.Spec.EksaVersion == nil {
config.Cluster.Spec.EksaVersion = &releaseVersion
}
eksaRelease := buildEKSARelease(release, bundlesManifest)

return NewSpec(config, bundlesManifest, eksdReleases, eksaRelease)
Expand Down
8 changes: 4 additions & 4 deletions pkg/features/features.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package features

// These are environment variables used as flags to enable/disable features.
const (
CloudStackKubeVipDisabledEnvVar = "CLOUDSTACK_KUBE_VIP_DISABLED"
CheckpointEnabledEnvVar = "CHECKPOINT_ENABLED"
UseNewWorkflowsEnvVar = "USE_NEW_WORKFLOWS"
UseControllerForWorkloadCli = "USE_CONTROLLER_FOR_WORKLOAD_CLI"
CloudStackKubeVipDisabledEnvVar = "CLOUDSTACK_KUBE_VIP_DISABLED"
CheckpointEnabledEnvVar = "CHECKPOINT_ENABLED"
UseNewWorkflowsEnvVar = "USE_NEW_WORKFLOWS"
UseControllerForWorkloadCli = "USE_CONTROLLER_FOR_WORKLOAD_CLI"
ExperimentalSelfManagedClusterUpgradeEnvVar = "EXP_SELF_MANAGED_API_UPGRADE"
ExperimentalSelfManagedClusterUpgradeGate = "ExpSelfManagedAPIUpgrade"
)
Expand Down
1 change: 1 addition & 0 deletions pkg/task/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type CommandContext struct {
PackageInstaller interfaces.PackageInstaller
EksdUpgrader interfaces.EksdUpgrader
ClusterUpgrader interfaces.ClusterUpgrader
ClusterCreater interfaces.ClusterCreater
CAPIManager interfaces.CAPIManager
ClusterSpec *cluster.Spec
CurrentClusterSpec *cluster.Spec
Expand Down
164 changes: 0 additions & 164 deletions pkg/workflows/createworkload.go

This file was deleted.

5 changes: 5 additions & 0 deletions pkg/workflows/interfaces/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,8 @@ type PackageInstaller interface {
type ClusterUpgrader interface {
Run(ctx context.Context, spec *cluster.Spec, managementCluster types.Cluster) error
}

// ClusterCreater creates the cluster and waits until it's ready.
type ClusterCreater interface {
Run(ctx context.Context, spec *cluster.Spec, managementCluster types.Cluster) error
}
63 changes: 63 additions & 0 deletions pkg/workflows/workload/create.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package workload

import (
"context"

"github.com/aws/eks-anywhere/pkg/cluster"
"github.com/aws/eks-anywhere/pkg/filewriter"
"github.com/aws/eks-anywhere/pkg/logger"
"github.com/aws/eks-anywhere/pkg/providers"
"github.com/aws/eks-anywhere/pkg/task"
"github.com/aws/eks-anywhere/pkg/workflows/interfaces"
)

// CreateWorkload is a schema for create cluster.
type CreateWorkload struct {
provider providers.Provider
clusterManager interfaces.ClusterManager
gitOpsManager interfaces.GitOpsManager
writer filewriter.FileWriter
// eksaSpec []byte
eksdInstaller interfaces.EksdInstaller
clusterCreater interfaces.ClusterCreater
packageInstaller interfaces.PackageInstaller
}

// NewCreateWorkload builds a new create construct.
func NewCreateWorkload(provider providers.Provider,
clusterManager interfaces.ClusterManager, gitOpsManager interfaces.GitOpsManager,
writer filewriter.FileWriter,
clusterCreate interfaces.ClusterCreater,
eksdInstaller interfaces.EksdInstaller,
packageInstaller interfaces.PackageInstaller,
) *CreateWorkload {
return &CreateWorkload{
provider: provider,
clusterManager: clusterManager,
gitOpsManager: gitOpsManager,
writer: writer,
eksdInstaller: eksdInstaller,
clusterCreater: clusterCreate,
packageInstaller: packageInstaller,
}
}

func (c *CreateWorkload) Run(ctx context.Context, clusterSpec *cluster.Spec, validator interfaces.Validator) error {
logger.Info("POC New workflow creating workload cluster using the controller")
commandContext := &task.CommandContext{
Provider: c.provider,
ClusterManager: c.clusterManager,
GitOpsManager: c.gitOpsManager,
ClusterSpec: clusterSpec,
Writer: c.writer,
Validations: validator,
ManagementCluster: clusterSpec.ManagementCluster,
ClusterCreater: c.clusterCreater,
}

// c.eksaSpec = eksaSpec

err := task.NewTaskRunner(&SetAndValidateWorkloadTask{}, c.writer).RunTask(ctx, commandContext)

return err
}
Loading

0 comments on commit 9cb8c74

Please sign in to comment.