Skip to content

Commit 1010c76

Browse files
feat(local) : adding a command to generate sample config file targetting cloud-provider=local
Signed-off-by: Archisman <archisman@obmondo.com>
1 parent e0df2ad commit 1010c76

6 files changed

Lines changed: 70 additions & 3 deletions

File tree

‎cmd/config/generate/generate.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,5 @@ func init() {
2929
// Subcommands.
3030
GenerateCmd.AddCommand(AWSCmd)
3131
GenerateCmd.AddCommand(HetznerCmd)
32+
GenerateCmd.AddCommand(LocalCmd)
3233
}

‎cmd/config/generate/hetzner.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
var HetznerCmd = &cobra.Command{
1212
Use: "hetzner",
1313

14-
Short: "Generate a sample KubeAid Bootstrap Script config file, for deploying an Hetzner based cluster",
14+
Short: "Generate a sample KubeAid Bootstrap Script config file, for deploying a Hetzner based cluster",
1515

1616
Run: func(cmd *cobra.Command, args []string) {
1717
config.GenerateSampleConfig(context.Background(), constants.CloudProviderHetzner)

‎cmd/config/generate/local.go‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package generate
2+
3+
import (
4+
"context"
5+
6+
"github.com/Obmondo/kubeaid-bootstrap-script/pkg/config"
7+
"github.com/Obmondo/kubeaid-bootstrap-script/pkg/constants"
8+
"github.com/spf13/cobra"
9+
)
10+
11+
var LocalCmd = &cobra.Command{
12+
Use: "local",
13+
14+
Short: "Generate a sample KubeAid Bootstrap Script config file, for deploying a local K3D based cluster (for testing purposes)",
15+
16+
Run: func(cmd *cobra.Command, args []string) {
17+
config.GenerateSampleConfig(context.Background(), constants.CloudProviderLocal)
18+
},
19+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Git credentials used to authenticate against the Git platform you're using (Github / Gitlab etc.).
2+
# KubeAid Bootstrap Script will use these credentials to :
3+
#
4+
# (1) Clone the KubeAid and KubeAid config repositories.
5+
# (2) Create and push commits to a branch in the KubeAid config repository.
6+
#
7+
# So, make sure the Git password (token) you're using has necessary permissions associated to do
8+
# the above.
9+
#
10+
# NOTE : Currently, we only support HTTPS authentication.
11+
git:
12+
username: xxxxxxxxxx
13+
password: xxxxxxxxxx
14+
15+
forks:
16+
# KubeAid repository URL (in HTTPs syntax).
17+
# Defaults to Obmondo's KubeAid repository.
18+
# kubeaid: https://github.com/Obmondo/KubeAid
19+
20+
# Your KubeAid config repository URL (in HTTPs syntax).
21+
kubeaidConfig: https://github.com/xxxxxxxxxx/kubeaid-config
22+
23+
# Kubernetes cluster and control-plane specific configurations.
24+
cluster:
25+
26+
# Kubernetes cluster name.
27+
name: kubeaid-demo-local
28+
29+
# Kubernetes version to use.
30+
# NOTE : Make sure that the AMI you're using, is targetted towards this Kubernetes version.
31+
k8sVersion: v1.31.0
32+
33+
# Kubeaid version to use.
34+
kubeaidVersion: 10.0.0
35+
36+
cloud:
37+
local: {}

‎pkg/config/generate_sample_config.go‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,25 @@ func GenerateSampleConfig(ctx context.Context, cloudProvider string) {
2626
case constants.CloudProviderHetzner:
2727
templateName = constants.TemplateNameHetznerSampleConfig
2828

29+
case constants.CloudProviderLocal:
30+
templateName = constants.TemplateNameLocalSampleConfig
31+
2932
default:
3033
panic("unreachable")
3134
}
3235

3336
content := templates.ParseAndExecuteTemplate(ctx, &SampleConfigs, templateName, nil)
3437

3538
destinationFile, err := os.OpenFile(constants.OutputPathGeneratedConfig, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0644)
36-
assert.AssertErrNil(ctx, err, "Failed opening file", slog.String("path", constants.OutputPathGeneratedConfig))
39+
assert.AssertErrNil(ctx, err,
40+
"Failed opening file",
41+
slog.String("path", constants.OutputPathGeneratedConfig),
42+
)
3743
defer destinationFile.Close()
3844

3945
_, err = destinationFile.Write(content)
40-
assert.AssertErrNil(ctx, err, "Failed writing sample config to file", slog.String("path", constants.OutputPathGeneratedConfig))
46+
assert.AssertErrNil(ctx, err,
47+
"Failed writing sample config to file",
48+
slog.String("path", constants.OutputPathGeneratedConfig),
49+
)
4150
}

‎pkg/constants/constants.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ const (
9191
var (
9292
TemplateNameAWSSampleConfig = "files/templates/aws.sample.config.yaml.tmpl"
9393
TemplateNameHetznerSampleConfig = "files/templates/hetzner.sample.config.yaml.tmpl"
94+
TemplateNameLocalSampleConfig = "files/templates/local.sample.config.yaml.tmpl"
9495

9596
CommonNonSecretTemplateNames = []string{
9697
// For ArgoCD.

0 commit comments

Comments
 (0)