Skip to content

Commit

Permalink
#29 - deprecate Terraform commands, add commands for managing CAPI
Browse files Browse the repository at this point in the history
  • Loading branch information
apanasiuk-el committed Sep 25, 2024
1 parent 8d4acd5 commit 7da2c5f
Show file tree
Hide file tree
Showing 12 changed files with 144 additions and 962 deletions.
483 changes: 12 additions & 471 deletions cmd/cluster.go

Large diffs are not rendered by default.

97 changes: 14 additions & 83 deletions cmd/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,8 @@ func Commands() []*cli.Command {
},
}
flags := Flags{
"clusterCRLogin": flagsClusterCRLogin(),
"clusterK3DCreate": flagsClusterK3DCreate(),
"clusterK3DImport": flagsClusterK3DImport(),
"clusterPlan": flagsClusterPlan(),
"clusterStateDelete": flagsClusterStateDelete(),
"clusterSwitch": flagsClusterSwitch(),
"config": flagsConfig(),
"configList": flagsConfigList(),
Expand Down Expand Up @@ -112,51 +109,33 @@ func Commands() []*cli.Command {
Usage: "Cluster management",
Subcommands: []*cli.Command{
{
Name: "container-registry",
Usage: "Container registry management",
Name: "capi",
Usage: "CAPI cluster management",
Aliases: []string{"c"},
Category: "cluster",
Subcommands: []*cli.Command{
{
Name: "login",
Usage: "Log in to container registry",
Before: readInputSourceWithContext(gitSpec, conf, flags["clusterCRLogin"]),
Flags: flags["clusterCRLogin"],
Category: "container-registry",
Name: "create",
Usage: "Create CAPI cluster",
Aliases: []string{"c"},
Before: readInputSourceWithContext(gitSpec, conf, flags["clusterK3DCreate"]),
Flags: flags["clusterK3DCreate"],
Category: "capi",
BashComplete: util.ShellCompleteCustomOutput,
Action: containerRegistryAction(conf, DockerRunner.dockerLogin),
Action: K3DCreateAction(conf),
},
{
Name: "logout",
Usage: "Log out from container registry",
Name: "delete",
Usage: "Delete CAPI cluster",
Aliases: []string{"d"},
Before: readInputSourceWithContext(gitSpec, conf, flags["hidden"]),
Flags: flags["hidden"],
Category: "container-registry",
Category: "capi",
BashComplete: util.ShellCompleteCustomOutput,
Action: containerRegistryAction(conf, DockerRunner.dockerLogout),
Action: K3DAction(conf, K3DRunner.createDeleteK3DCluster),
},
},
},
{
Name: "destroy",
Usage: "Destroy AWS cluster using Terraform",
Aliases: []string{"d"},
Before: readInputSourceWithContext(gitSpec, conf, flags["hidden"]),
Flags: flags["hidden"],
Category: "cluster",
BashComplete: util.ShellCompleteCustomOutput,
Action: clusterDestroyAction(conf),
},
{
Name: "list",
Usage: "List all Terraform available workspaces",
Aliases: []string{"l"},
Before: readInputSourceWithContext(gitSpec, conf, flags["hidden"]),
Flags: flags["hidden"],
Category: "cluster",
BashComplete: util.ShellCompleteCustomOutput,
Action: clusterListAction(conf),
},
{
Name: "k3d",
Usage: "K3D cluster management",
Expand Down Expand Up @@ -224,54 +203,6 @@ func Commands() []*cli.Command {
},
},
},
{
Name: "provision",
Usage: "Provision AWS cluster using Terraform",
Aliases: []string{"p"},
Before: readInputSourceWithContext(gitSpec, conf, flags["clusterPlan"]),
Flags: flags["clusterPlan"],
Category: "cluster",
BashComplete: util.ShellCompleteCustomOutput,
Action: clusterProvisionAction(conf),
},
{
Name: "state",
Usage: "State cluster management using Terraform",
Aliases: []string{"t"},
Category: "cluster",
Subcommands: []*cli.Command{
{
Name: "delete",
Usage: "Delete resource from Terraform state",
Aliases: []string{"d"},
Before: readInputSourceWithContext(gitSpec, conf, flags["clusterStateDelete"]),
Flags: flags["clusterStateDelete"],
Category: "state",
BashComplete: util.ShellCompleteCustomOutput,
Action: clusterStateAction(conf, StateRunner.clusterStateDelete),
},
{
Name: "list",
Usage: "List resources from Terraform state",
Aliases: []string{"l"},
Before: readInputSourceWithContext(gitSpec, conf, flags["hidden"]),
Flags: flags["hidden"],
Category: "state",
BashComplete: util.ShellCompleteCustomOutput,
Action: clusterStateAction(conf, StateRunner.clusterStateList),
},
{
Name: "refresh",
Usage: "Update state file for AWS cluster using Terraform",
Aliases: []string{"r"},
Before: readInputSourceWithContext(gitSpec, conf, flags["hidden"]),
Flags: flags["hidden"],
Category: "state",
BashComplete: util.ShellCompleteCustomOutput,
Action: clusterStateAction(conf, StateRunner.clusterStateRefresh),
},
},
},
{
Name: "switch",
Usage: "Switch Kubernetes context for tenant cluster",
Expand Down
29 changes: 4 additions & 25 deletions cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,8 +374,6 @@ func getConfigFromEnvironment(c *cli.Context, conf *config.Config, gitSpec *git_
}

if c.String("cluster-provider") == util.AWSClusterProvider {
conf.AwsConfigure = new(aws_provider.AwsConfigure)

if err := c.Set("config-name-from", conf.Name); err != nil {
return err
}
Expand Down Expand Up @@ -458,7 +456,6 @@ func getConfigFromEnvironment(c *cli.Context, conf *config.Config, gitSpec *git_
}

conf.ConfigNameFrom = c.String("config-name-from")
conf.CloudflareToken = c.String("cloudflare-token")
conf.GitHubToken = c.String("github-token")

return nil
Expand Down Expand Up @@ -535,14 +532,9 @@ func configInitAction(conf *config.Config, gitSpec *git_handler.GitSpec) cli.Act

switch conf.ClusterProvider {
case util.AWSClusterProvider:
conf.Terraform.BucketKey = util.TenantBucketKey
conf.ClusterProvisionerSL = c.Bool("cluster-provisioner-state-locking")
conf.AwsConfigure.Profile = gitSpec.ID
conf.AWSMFAProfile = c.String("aws-mfa-profile")
conf.AWSMFATokenExpiration = c.String("aws-mfa-token-expiration")
conf.AWSECRHost = c.String("aws-ecr-host")
conf.AWSECRRegion = c.String("aws-ecr-region")
conf.AWSECRUserName = c.String("aws-ecr-user-name")

// AWS Profile init configuration with support MFA
if err := initAWSProfile(c, conf, gitSpec); err != nil {
Expand All @@ -554,13 +546,12 @@ func configInitAction(conf *config.Config, gitSpec *git_handler.GitSpec) cli.Act
awsUID := conf.AccountID[0:3] + conf.AccountID[len(conf.AccountID)-2:]
conf.SopsAgeKeys = util.GetHomePath(util.RMKDir, util.SopsRootName, conf.Tenant+"-"+util.SopsRootName+"-"+awsUID)
conf.SopsBucketName = conf.Tenant + "-" + util.SopsRootName + "-" + awsUID
conf.Terraform.BucketName = conf.Tenant + "-" + util.TenantBucketName + "-" + awsUID
conf.Terraform.DDBTableName = util.TenantDDBTablePrefix + "-" + awsUID
case util.LocalClusterProvider:
conf.AwsConfigure = &aws_provider.AwsConfigure{}
conf.SopsAgeKeys = util.GetHomePath(util.RMKDir, util.SopsRootName, conf.Tenant+"-"+util.SopsRootName+"-"+util.LocalClusterProvider)
}

if err := conf.InitConfig(true).SetRootDomain(c, gitSpec.ID); err != nil {
if err := conf.InitConfig().SetRootDomain(c, gitSpec.ID); err != nil {
return err
}

Expand All @@ -569,18 +560,6 @@ func configInitAction(conf *config.Config, gitSpec *git_handler.GitSpec) cli.Act
}

if conf.ClusterProvider == util.AWSClusterProvider {
if conf.ClusterProvisionerSL {
// create dynamodb table for backend terraform
if err := conf.CreateDynamoDBTable(conf.Terraform.DDBTableName); err != nil {
return err
}
}

// create s3 bucket for backend terraform
if err := conf.CreateBucket(conf.Terraform.BucketName); err != nil {
return err
}

//create s3 bucket for sops age keys
if err := conf.CreateBucket(conf.SopsBucketName); err != nil {
return err
Expand All @@ -590,7 +569,7 @@ func configInitAction(conf *config.Config, gitSpec *git_handler.GitSpec) cli.Act
return err
}

if err := resolveDependencies(conf.InitConfig(true), c, false); err != nil {
if err := resolveDependencies(conf.InitConfig(), c, false); err != nil {
return err
}

Expand All @@ -599,7 +578,7 @@ func configInitAction(conf *config.Config, gitSpec *git_handler.GitSpec) cli.Act
return nil
}

if err := resolveDependencies(conf.InitConfig(false), c, false); err != nil {
if err := resolveDependencies(conf.InitConfig(), c, false); err != nil {
return err
}

Expand Down
91 changes: 0 additions & 91 deletions cmd/container_registry.go

This file was deleted.

Loading

0 comments on commit 7da2c5f

Please sign in to comment.