-
Notifications
You must be signed in to change notification settings - Fork 7
feat: deploy-cli for scaffolding #839
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+1,708
−0
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| root = true | ||
|
|
||
| [*] | ||
| charset = utf-8 | ||
| indent_style = space | ||
| indent_size = 2 | ||
| end_of_line = lf | ||
| #insert_final_newline = true | ||
| trim_trailing_whitespace = true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| # Binaries for programs and plugins | ||
| *.exe | ||
| *.exe~ | ||
| *.dll | ||
| *.so | ||
| *.dylib | ||
|
|
||
| # Test binary, built with `go hugo -c` | ||
| *.test | ||
|
|
||
| # Output of the go coverage tool, specifically when used with LiteIDE | ||
| *.out | ||
|
|
||
| # Dependency directories (remove the comment below to include it) | ||
| vendor/ | ||
|
|
||
| # VsCode | ||
|
|
||
| .vsscode/* | ||
| .vscode/ | ||
|
|
||
| # goreleaser dist folder | ||
| dist/ | ||
|
|
||
| # IntelliJ | ||
| .idea | ||
| *.iml | ||
| .idea/workspace.xml | ||
| .idea/tasks.xml | ||
| .idea/gradle.xml | ||
| .idea/assetWizardSettings.xml | ||
| .idea/dictionaries | ||
| .idea/libraries | ||
| .idea/caches |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| # This is an example .goreleaser.yml file with some sensible defaults. | ||
| # Make sure to check the documentation at https://goreleaser.com | ||
|
|
||
| # The lines below are called `modelines`. See `:help modeline` | ||
| # Feel free to remove those if you don't want/need to use them. | ||
| # yaml-language-server: $schema=https://goreleaser.com/static/schema.json | ||
| # vim: set ts=2 sw=2 tw=0 fo=cnqoj | ||
|
|
||
| version: 2 | ||
|
|
||
| before: | ||
| hooks: | ||
| # You may remove this if you don't use go modules. | ||
| - go mod tidy | ||
|
|
||
| builds: | ||
| - env: | ||
| - CGO_ENABLED=0 | ||
| goos: ["linux", "darwin", "windows"] | ||
| goarch: ["386", "amd64", "arm64"] | ||
| binary: deploy-cli | ||
| ldflags: | ||
| - -s -w -X "main.version={{.Version}}" | ||
|
|
||
| universal_binaries: | ||
| - replace: true | ||
|
|
||
| archives: | ||
| - formats: [tar.gz] | ||
| # this name template makes the OS and Arch compatible with the results of `uname`. | ||
| name_template: >- | ||
| {{ .ProjectName }}_ | ||
| {{- title .Os }}_ | ||
| {{- if eq .Arch "amd64" }}x86_64 | ||
| {{- else if eq .Arch "386" }}i386 | ||
| {{- else }}{{ .Arch }}{{ end }} | ||
| {{- if .Arm }}v{{ .Arm }}{{ end }} | ||
| # use zip for windows archives | ||
| format_overrides: | ||
| - goos: windows | ||
| formats: [zip] | ||
|
|
||
| changelog: | ||
| sort: asc | ||
| filters: | ||
| exclude: | ||
| - "^docs:" | ||
| - "^test:" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| # undercloud-deploy-cli | ||
|
|
||
| Undercloud Deploy cli helps quickly generate undercloud-deploy config files. | ||
|
|
||
|
|
||
| ## How to use. | ||
|
|
||
| > Please make sure that you have kubeseal binary installed your system https://github.com/bitnami-labs/sealed-secrets | ||
|
|
||
| * Export all these env | ||
|
|
||
| ```sh | ||
| export UC_DEPLOY="<full_local_path_to_undercloud_deploy_repo>" | ||
| export DEPLOY_NAME="<cluster_name>" | ||
| export UC_DEPLOY_GIT_URL=git@github.com:RSS-Engineering/undercloud-deploy.git | ||
| export UC_DEPLOY_SSH_FILE=<path_to_ssh_private_key_file> | ||
| export DNS_ZONE=<cluster_name>.dev.undercloud.rackspace.net | ||
| export UC_DEPLOY_EMAIL="<your_email>" | ||
| export UC_AIO=yes | ||
| ``` | ||
|
|
||
| * Run | ||
|
|
||
| ``` | ||
| go run *.go init | ||
| go run *.go help | ||
| ``` | ||
|
|
||
| * Commit all changes to the undercloud-deploy repo in your branch | ||
|
|
||
|
|
||
| ## Contributing | ||
|
|
||
| If you find any issues or have suggestions for improvements, please open an issue on the [GitHub repository](https://github.com/rackerlabs/understack). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| package argocd | ||
|
|
||
| import ( | ||
| _ "embed" | ||
| "fmt" | ||
| "os" | ||
| "path/filepath" | ||
|
|
||
| "github.com/rackerlabs/understack/go/deploy-cli/cmd" | ||
| "github.com/rackerlabs/understack/go/deploy-cli/helpers" | ||
|
|
||
| "github.com/charmbracelet/log" | ||
| "github.com/gookit/goutil/envutil" | ||
| "github.com/gookit/goutil/fsutil" | ||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| //go:embed templates/argoCluster.tmpl | ||
| var argoClusterTemplate string | ||
|
|
||
| //go:embed templates/argoSecretDeployRepo.tmpl | ||
| var argoSecretDeployRepoTemplate string | ||
|
|
||
| // Constants for file paths and template names | ||
| const ( | ||
| clusterSecretFile = "secret-%s-cluster.yaml" | ||
| secretDeployRepoFile = "secret-deploy-repo.yaml" | ||
| argoNamespace = "argocd" | ||
| ) | ||
|
|
||
| var ArgoCMD = &cobra.Command{ | ||
| Use: "argocd-secrets", | ||
| Short: "Generate ArgoCD secrets", | ||
| Long: "Generate repository and cluster secrets for ArgoCD deployment", | ||
| Run: func(cmd *cobra.Command, args []string) { | ||
| if err := GenerateSecrets(); err != nil { | ||
| log.Fatal("Failed to generate secrets", "error", err) | ||
| os.Exit(1) | ||
| } | ||
| }, | ||
| } | ||
|
|
||
| func init() { | ||
| cmd.RootCmd.AddCommand(ArgoCMD) | ||
| } | ||
|
|
||
| // GenerateSecrets orchestrates the generation of all ArgoCD secrets | ||
| func GenerateSecrets() error { | ||
| basePath := helpers.GetManifestPathToService("argocd") | ||
|
|
||
| if err := generateDeployRepoSecret(basePath); err != nil { | ||
| return fmt.Errorf("deploy repo secret generation failed: %w", err) | ||
| } | ||
|
|
||
| if err := generateClusterSecret(basePath); err != nil { | ||
| return fmt.Errorf("cluster secret generation failed: %w", err) | ||
| } | ||
|
|
||
| helpers.UpdateKustomizeFile(basePath) | ||
| return nil | ||
| } | ||
|
|
||
| // generateDeployRepoSecret generates the repository deployment secret | ||
| func generateDeployRepoSecret(basePath string) error { | ||
| vars := map[string]any{ | ||
| "Config": `{"tlsClientConfig":{"insecure":false}}`, | ||
| "Name": envutil.Getenv("UC_DEPLOY"), | ||
| "Server": "https://kubernetes.default.svc", | ||
| "DEPLOY_NAME": envutil.Getenv("DEPLOY_NAME"), | ||
| "UC_DEPLOY_GIT_URL": envutil.Getenv("UC_DEPLOY_GIT_URL"), | ||
| "DNS_ZONE": envutil.Getenv("DNS_ZONE"), | ||
| } | ||
|
|
||
| result, err := helpers.TemplateHelper(argoSecretDeployRepoTemplate, vars) | ||
| if err != nil { | ||
| return fmt.Errorf("template rendering failed: %w", err) | ||
| } | ||
|
|
||
| outputFilePath := filepath.Join(basePath, fmt.Sprintf(clusterSecretFile, envutil.Getenv("DEPLOY_NAME"))) | ||
|
|
||
| return writeToFile(outputFilePath, result) | ||
| } | ||
|
|
||
| // generateClusterSecret generates the cluster secret | ||
| func generateClusterSecret(basePath string) error { | ||
| vars := map[string]any{ | ||
| "DEPLOY_NAME": envutil.Getenv("DEPLOY_NAME"), | ||
| "Type": "git", | ||
| "UC_DEPLOY_GIT_URL": envutil.Getenv("UC_DEPLOY_GIT_URL"), | ||
| "DNS_ZONE": envutil.Getenv("DNS_ZONE"), | ||
| "UC_DEPLOY_SSH_FILE": envutil.Getenv("UC_DEPLOY_SSH_FILE"), | ||
| } | ||
|
|
||
| result, err := helpers.TemplateHelper(argoClusterTemplate, vars) | ||
| if err != nil { | ||
| return fmt.Errorf("template rendering failed: %w", err) | ||
| } | ||
|
|
||
| outputFilePath := filepath.Join(basePath, secretDeployRepoFile) | ||
| return writeToFile(outputFilePath, result) | ||
| } | ||
|
|
||
| // writeToFile writes content to a file with proper permissions | ||
| func writeToFile(filePath string, content string) error { | ||
| err := fsutil.WriteFile(filePath, content, os.ModePerm) | ||
| if err != nil { | ||
| return fmt.Errorf("file write failed: %w", err) | ||
| } | ||
| return nil | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| --- | ||
| apiVersion: v1 | ||
| kind: Secret | ||
| metadata: | ||
| name: {{ .DEPLOY_NAME }}-repo | ||
| namespace: argocd | ||
| labels: | ||
| argocd.argoproj.io/secret-type: repo-creds | ||
| data: | ||
| sshPrivateKey: {{ .UC_DEPLOY_SSH_FILE }} | ||
| type: {{ .Type | b64enc }} | ||
| url: {{ .UC_DEPLOY_GIT_URL | b64enc }} |
19 changes: 19 additions & 0 deletions
19
go/deploy-cli/cmd/argocd/templates/argoSecretDeployRepo.tmpl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| --- | ||
| apiVersion: v1 | ||
| kind: Secret | ||
| data: | ||
| config: {{ .Config | b64enc }} | ||
| name: {{ .Name | b64enc }} | ||
| server: {{ .Server | b64enc }} | ||
| metadata: | ||
| name: {{ .DEPLOY_NAME }}-cluster | ||
| namespace: argocd | ||
| labels: | ||
| argocd.argoproj.io/secret-type: cluster | ||
| understack.rackspace.com/argocd: enabled | ||
| annotations: | ||
| uc_repo_git_url: "https://github.com/rackerlabs/understack.git" | ||
| uc_repo_ref: "HEAD" | ||
| uc_deploy_git_url: "{{ .UC_DEPLOY_GIT_URL }}" | ||
| uc_deploy_ref: "HEAD" | ||
| dns_zone: "{{ .DNS_ZONE }}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| package certManager | ||
|
|
||
| import ( | ||
| _ "embed" | ||
| "fmt" | ||
| "os" | ||
|
|
||
| "github.com/rackerlabs/understack/go/deploy-cli/cmd" | ||
| "github.com/rackerlabs/understack/go/deploy-cli/helpers" | ||
|
|
||
| "github.com/charmbracelet/log" | ||
| "github.com/gookit/goutil/envutil" | ||
| "github.com/gookit/goutil/fsutil" | ||
|
|
||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| //go:embed templates/clusterIssuer.tmpl | ||
| var clusterIssuerTemplate string | ||
|
|
||
| func init() { | ||
| cmd.RootCmd.AddCommand(CertManager) | ||
| } | ||
|
|
||
| var CertManager = &cobra.Command{ | ||
| Use: "certmanager-secrets", | ||
| Short: "Generate certmanager-secrets secrets", | ||
| Long: "", | ||
| Run: certManagerGen, | ||
| } | ||
|
|
||
| func certManagerGen(cmd *cobra.Command, args []string) { | ||
| err := clusterIssuer() | ||
| if err != nil { | ||
| log.Error("certManagerGen failed", "error", err) | ||
| } | ||
| } | ||
|
|
||
| // credGen prints out the cli version number | ||
| func clusterIssuer() error { | ||
| vars := map[string]any{ | ||
| "UC_DEPLOY_EMAIL": envutil.Getenv("UC_DEPLOY_EMAIL"), | ||
| "DNS_ZONE": envutil.Getenv("DNS_ZONE"), | ||
| } | ||
|
|
||
| result, err := helpers.TemplateHelper(string(clusterIssuerTemplate), vars) | ||
| if err != nil { | ||
| return fmt.Errorf("template rendering failed: %w", err) | ||
| } | ||
|
|
||
| outputFilePath := helpers.GetManifestPathToService("cert-manager") + "/cluster-issuer.yaml" | ||
|
|
||
| if err := fsutil.WriteFile(outputFilePath, result, os.ModePerm); err != nil { | ||
| log.Fatal("error in kustomization.yaml file", "err", err) | ||
| os.Exit(1) | ||
| } | ||
| helpers.UpdateKustomizeFile(helpers.GetManifestPathToService("cert-manager")) | ||
|
|
||
| return nil | ||
| } |
27 changes: 27 additions & 0 deletions
27
go/deploy-cli/cmd/certManager/templates/clusterIssuer.tmpl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| --- | ||
| apiVersion: cert-manager.io/v1 | ||
| kind: ClusterIssuer | ||
| metadata: | ||
| name: understack-cluster-issuer | ||
| annotations: | ||
| argocd.argoproj.io/sync-wave: "5" | ||
| spec: | ||
| acme: | ||
| email: {{ .UC_DEPLOY_EMAIL }} | ||
| privateKeySecretRef: | ||
| name: letsencrypt-prod | ||
| server: https://acme-v02.api.letsencrypt.org/directory | ||
| solvers: | ||
| - http01: | ||
| ingress: | ||
| ingressClassName: nginx | ||
| selector: | ||
| matchLabels: | ||
| authorizeWith: http | ||
| - dns01: | ||
| webhook: | ||
| groupName: acme.undercloud.rackspace.net | ||
| solverName: rackspace | ||
| config: | ||
| authSecretRef: cert-manager-webhook-rackspace-creds | ||
| domainName: {{ .DNS_ZONE }} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.