diff --git a/cmd/gotk/bootstrap.go b/cmd/gotk/bootstrap.go index 33b2d180..c68261aa 100644 --- a/cmd/gotk/bootstrap.go +++ b/cmd/gotk/bootstrap.go @@ -23,7 +23,6 @@ import ( "os" "path" "path/filepath" - "sigs.k8s.io/yaml" "strings" "time" @@ -33,6 +32,7 @@ import ( "k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/util/wait" "sigs.k8s.io/controller-runtime/pkg/client" + "sigs.k8s.io/yaml" kustomizev1 "github.com/fluxcd/kustomize-controller/api/v1alpha1" sourcev1 "github.com/fluxcd/source-controller/api/v1alpha1" @@ -49,6 +49,7 @@ var ( bootstrapComponents []string bootstrapRegistry string bootstrapImagePullSecret string + bootstrapArch string ) const ( @@ -67,6 +68,8 @@ func init() { "container registry where the toolkit images are published") bootstrapCmd.PersistentFlags().StringVar(&bootstrapImagePullSecret, "image-pull-secret", "", "Kubernetes secret name used for pulling the toolkit images from a private registry") + bootstrapCmd.PersistentFlags().StringVar(&bootstrapArch, "arch", "amd64", + "arch can be amd64 or arm64") rootCmd.AddCommand(bootstrapCmd) } @@ -78,7 +81,7 @@ func generateInstallManifests(targetPath, namespace, tmpDir string) (string, err return "", fmt.Errorf("generating manifests failed: %w", err) } - if err := genInstallManifests(bootstrapVersion, namespace, bootstrapComponents, bootstrapRegistry, bootstrapImagePullSecret, gotkDir); err != nil { + if err := genInstallManifests(bootstrapVersion, namespace, bootstrapComponents, bootstrapRegistry, bootstrapImagePullSecret, bootstrapArch, gotkDir); err != nil { return "", fmt.Errorf("generating manifests failed: %w", err) } diff --git a/cmd/gotk/bootstrap_github.go b/cmd/gotk/bootstrap_github.go index cba98cde..bd8b83ee 100644 --- a/cmd/gotk/bootstrap_github.go +++ b/cmd/gotk/bootstrap_github.go @@ -93,6 +93,10 @@ func bootstrapGitHubCmdRun(cmd *cobra.Command, args []string) error { return fmt.Errorf("%s environment variable not found", git.GitHubTokenName) } + if !utils.containsItemString(supportedArch, bootstrapArch) { + return fmt.Errorf("arch %s is not supported, can be %v", bootstrapArch, supportedArch) + } + repository, err := git.NewRepository(ghRepository, ghOwner, ghHostname, ghToken, "gotk", ghOwner+"@users.noreply.github.com") if err != nil { return err diff --git a/cmd/gotk/bootstrap_gitlab.go b/cmd/gotk/bootstrap_gitlab.go index 7043c786..cf2c8c4f 100644 --- a/cmd/gotk/bootstrap_gitlab.go +++ b/cmd/gotk/bootstrap_gitlab.go @@ -86,6 +86,10 @@ func bootstrapGitLabCmdRun(cmd *cobra.Command, args []string) error { return fmt.Errorf("%s environment variable not found", git.GitLabTokenName) } + if !utils.containsItemString(supportedArch, bootstrapArch) { + return fmt.Errorf("arch %s is not supported, can be %v", bootstrapArch, supportedArch) + } + repository, err := git.NewRepository(glRepository, glOwner, glHostname, glToken, "gotk", glOwner+"@users.noreply.gitlab.com") if err != nil { return err diff --git a/cmd/gotk/install.go b/cmd/gotk/install.go index fe176115..2069609d 100644 --- a/cmd/gotk/install.go +++ b/cmd/gotk/install.go @@ -19,7 +19,6 @@ package main import ( "context" "fmt" - "github.com/fluxcd/pkg/untar" "io/ioutil" "net/http" "os" @@ -31,6 +30,8 @@ import ( "github.com/spf13/cobra" "sigs.k8s.io/kustomize/api/filesys" "sigs.k8s.io/kustomize/api/krusty" + + "github.com/fluxcd/pkg/untar" ) var installCmd = &cobra.Command{ @@ -61,6 +62,7 @@ var ( installComponents []string installRegistry string installImagePullSecret string + installArch string ) func init() { @@ -78,10 +80,16 @@ func init() { "container registry where the toolkit images are published") installCmd.Flags().StringVar(&installImagePullSecret, "image-pull-secret", "", "Kubernetes secret name used for pulling the toolkit images from a private registry") + installCmd.Flags().StringVar(&installArch, "arch", "amd64", + "arch can be amd64 or arm64") rootCmd.AddCommand(installCmd) } func installCmdRun(cmd *cobra.Command, args []string) error { + if !utils.containsItemString(supportedArch, installArch) { + return fmt.Errorf("arch %s is not supported, can be %v", installArch, supportedArch) + } + ctx, cancel := context.WithTimeout(context.Background(), timeout) defer cancel() @@ -103,7 +111,7 @@ func installCmdRun(cmd *cobra.Command, args []string) error { logger.Generatef("generating manifests") } if kustomizePath == "" { - err = genInstallManifests(installVersion, namespace, installComponents, installRegistry, installImagePullSecret, tmpDir) + err = genInstallManifests(installVersion, namespace, installComponents, installRegistry, installImagePullSecret, installArch, tmpDir) if err != nil { return fmt.Errorf("install failed: %w", err) } @@ -192,6 +200,7 @@ fieldSpecs: var kustomizationTmpl = `--- {{- $eventsAddr := .EventsAddr }} {{- $registry := .Registry }} +{{- $arch := .Arch }} apiVersion: kustomize.config.k8s.io/v1beta1 kind: Kustomization namespace: {{.Namespace}} @@ -231,7 +240,11 @@ patchesJson6902: images: {{- range $i, $component := .Components }} - name: fluxcd/{{$component}} +{{- if eq $arch "amd64" }} newName: {{$registry}}/{{$component}} +{{- else }} + newName: {{$registry}}/{{$component}}-{{$arch}} +{{- end }} {{- end }} {{- end }} ` @@ -253,7 +266,7 @@ spec: template: spec: nodeSelector: - kubernetes.io/arch: amd64 + kubernetes.io/arch: {{.Arch}} kubernetes.io/os: linux {{- if .ImagePullSecret }} imagePullSecrets: @@ -295,7 +308,7 @@ func downloadManifests(version string, tmpDir string) error { return nil } -func genInstallManifests(version string, namespace string, components []string, registry, imagePullSecret, tmpDir string) error { +func genInstallManifests(version string, namespace string, components []string, registry, imagePullSecret, arch, tmpDir string) error { eventsAddr := "" if utils.containsItemString(components, defaultNotification) { eventsAddr = fmt.Sprintf("http://%s/", defaultNotification) @@ -308,6 +321,7 @@ func genInstallManifests(version string, namespace string, components []string, EventsAddr string Registry string ImagePullSecret string + Arch string }{ Version: version, Namespace: namespace, @@ -315,6 +329,7 @@ func genInstallManifests(version string, namespace string, components []string, EventsAddr: eventsAddr, Registry: registry, ImagePullSecret: imagePullSecret, + Arch: arch, } if err := downloadManifests(version, tmpDir); err != nil { diff --git a/cmd/gotk/main.go b/cmd/gotk/main.go index 8ba5a45c..cad7015b 100644 --- a/cmd/gotk/main.go +++ b/cmd/gotk/main.go @@ -108,6 +108,7 @@ var ( defaultVersion = "latest" defaultNamespace = "gitops-system" defaultNotification = "notification-controller" + supportedArch = []string{"arm64", "amd64"} ) func init() { diff --git a/docs/cmd/gotk_bootstrap.md b/docs/cmd/gotk_bootstrap.md index aaa3f81c..e3cf9bfa 100644 --- a/docs/cmd/gotk_bootstrap.md +++ b/docs/cmd/gotk_bootstrap.md @@ -9,6 +9,7 @@ The bootstrap sub-commands bootstrap the toolkit components on the targeted Git ### Options ``` + --arch string arch can be amd64 or arm64 (default "amd64") --components strings list of components, accepts comma-separated values (default [source-controller,kustomize-controller,helm-controller,notification-controller]) -h, --help help for bootstrap --image-pull-secret string Kubernetes secret name used for pulling the toolkit images from a private registry diff --git a/docs/cmd/gotk_bootstrap_github.md b/docs/cmd/gotk_bootstrap_github.md index 1162a0d1..947adae9 100644 --- a/docs/cmd/gotk_bootstrap_github.md +++ b/docs/cmd/gotk_bootstrap_github.md @@ -54,6 +54,7 @@ gotk bootstrap github [flags] ### Options inherited from parent commands ``` + --arch string arch can be amd64 or arm64 (default "amd64") --components strings list of components, accepts comma-separated values (default [source-controller,kustomize-controller,helm-controller,notification-controller]) --image-pull-secret string Kubernetes secret name used for pulling the toolkit images from a private registry --kubeconfig string path to the kubeconfig file (default "~/.kube/config") diff --git a/docs/cmd/gotk_bootstrap_gitlab.md b/docs/cmd/gotk_bootstrap_gitlab.md index dda38ac1..5b7d7165 100644 --- a/docs/cmd/gotk_bootstrap_gitlab.md +++ b/docs/cmd/gotk_bootstrap_gitlab.md @@ -51,6 +51,7 @@ gotk bootstrap gitlab [flags] ### Options inherited from parent commands ``` + --arch string arch can be amd64 or arm64 (default "amd64") --components strings list of components, accepts comma-separated values (default [source-controller,kustomize-controller,helm-controller,notification-controller]) --image-pull-secret string Kubernetes secret name used for pulling the toolkit images from a private registry --kubeconfig string path to the kubeconfig file (default "~/.kube/config") diff --git a/docs/cmd/gotk_install.md b/docs/cmd/gotk_install.md index a8096fe5..16f63878 100644 --- a/docs/cmd/gotk_install.md +++ b/docs/cmd/gotk_install.md @@ -31,6 +31,7 @@ gotk install [flags] ### Options ``` + --arch string arch can be amd64 or arm64 (default "amd64") --components strings list of components, accepts comma-separated values (default [source-controller,kustomize-controller,helm-controller,notification-controller]) --dry-run only print the object that would be applied --export write the install manifests to stdout and exit