mirror of
https://github.com/fluxcd/flux2.git
synced 2026-02-24 08:31:47 +00:00
Add arch flag to install/bootstrap
This commit is contained in:
parent
6b397cff73
commit
3f07bd6471
9 changed files with 37 additions and 6 deletions
|
|
@ -23,7 +23,6 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sigs.k8s.io/yaml"
|
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
|
@ -33,6 +32,7 @@ import (
|
||||||
"k8s.io/apimachinery/pkg/types"
|
"k8s.io/apimachinery/pkg/types"
|
||||||
"k8s.io/apimachinery/pkg/util/wait"
|
"k8s.io/apimachinery/pkg/util/wait"
|
||||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||||
|
"sigs.k8s.io/yaml"
|
||||||
|
|
||||||
kustomizev1 "github.com/fluxcd/kustomize-controller/api/v1alpha1"
|
kustomizev1 "github.com/fluxcd/kustomize-controller/api/v1alpha1"
|
||||||
sourcev1 "github.com/fluxcd/source-controller/api/v1alpha1"
|
sourcev1 "github.com/fluxcd/source-controller/api/v1alpha1"
|
||||||
|
|
@ -49,6 +49,7 @@ var (
|
||||||
bootstrapComponents []string
|
bootstrapComponents []string
|
||||||
bootstrapRegistry string
|
bootstrapRegistry string
|
||||||
bootstrapImagePullSecret string
|
bootstrapImagePullSecret string
|
||||||
|
bootstrapArch string
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
@ -67,6 +68,8 @@ func init() {
|
||||||
"container registry where the toolkit images are published")
|
"container registry where the toolkit images are published")
|
||||||
bootstrapCmd.PersistentFlags().StringVar(&bootstrapImagePullSecret, "image-pull-secret", "",
|
bootstrapCmd.PersistentFlags().StringVar(&bootstrapImagePullSecret, "image-pull-secret", "",
|
||||||
"Kubernetes secret name used for pulling the toolkit images from a private registry")
|
"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)
|
rootCmd.AddCommand(bootstrapCmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -78,7 +81,7 @@ func generateInstallManifests(targetPath, namespace, tmpDir string) (string, err
|
||||||
return "", fmt.Errorf("generating manifests failed: %w", 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)
|
return "", fmt.Errorf("generating manifests failed: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -93,6 +93,10 @@ func bootstrapGitHubCmdRun(cmd *cobra.Command, args []string) error {
|
||||||
return fmt.Errorf("%s environment variable not found", git.GitHubTokenName)
|
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")
|
repository, err := git.NewRepository(ghRepository, ghOwner, ghHostname, ghToken, "gotk", ghOwner+"@users.noreply.github.com")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
||||||
|
|
@ -86,6 +86,10 @@ func bootstrapGitLabCmdRun(cmd *cobra.Command, args []string) error {
|
||||||
return fmt.Errorf("%s environment variable not found", git.GitLabTokenName)
|
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")
|
repository, err := git.NewRepository(glRepository, glOwner, glHostname, glToken, "gotk", glOwner+"@users.noreply.gitlab.com")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,6 @@ package main
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/fluxcd/pkg/untar"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
|
@ -31,6 +30,8 @@ import (
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"sigs.k8s.io/kustomize/api/filesys"
|
"sigs.k8s.io/kustomize/api/filesys"
|
||||||
"sigs.k8s.io/kustomize/api/krusty"
|
"sigs.k8s.io/kustomize/api/krusty"
|
||||||
|
|
||||||
|
"github.com/fluxcd/pkg/untar"
|
||||||
)
|
)
|
||||||
|
|
||||||
var installCmd = &cobra.Command{
|
var installCmd = &cobra.Command{
|
||||||
|
|
@ -61,6 +62,7 @@ var (
|
||||||
installComponents []string
|
installComponents []string
|
||||||
installRegistry string
|
installRegistry string
|
||||||
installImagePullSecret string
|
installImagePullSecret string
|
||||||
|
installArch string
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|
@ -78,10 +80,16 @@ func init() {
|
||||||
"container registry where the toolkit images are published")
|
"container registry where the toolkit images are published")
|
||||||
installCmd.Flags().StringVar(&installImagePullSecret, "image-pull-secret", "",
|
installCmd.Flags().StringVar(&installImagePullSecret, "image-pull-secret", "",
|
||||||
"Kubernetes secret name used for pulling the toolkit images from a private registry")
|
"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)
|
rootCmd.AddCommand(installCmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
func installCmdRun(cmd *cobra.Command, args []string) error {
|
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)
|
ctx, cancel := context.WithTimeout(context.Background(), timeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
|
|
@ -103,7 +111,7 @@ func installCmdRun(cmd *cobra.Command, args []string) error {
|
||||||
logger.Generatef("generating manifests")
|
logger.Generatef("generating manifests")
|
||||||
}
|
}
|
||||||
if kustomizePath == "" {
|
if kustomizePath == "" {
|
||||||
err = genInstallManifests(installVersion, namespace, installComponents, installRegistry, installImagePullSecret, tmpDir)
|
err = genInstallManifests(installVersion, namespace, installComponents, installRegistry, installImagePullSecret, installArch, tmpDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("install failed: %w", err)
|
return fmt.Errorf("install failed: %w", err)
|
||||||
}
|
}
|
||||||
|
|
@ -192,6 +200,7 @@ fieldSpecs:
|
||||||
var kustomizationTmpl = `---
|
var kustomizationTmpl = `---
|
||||||
{{- $eventsAddr := .EventsAddr }}
|
{{- $eventsAddr := .EventsAddr }}
|
||||||
{{- $registry := .Registry }}
|
{{- $registry := .Registry }}
|
||||||
|
{{- $arch := .Arch }}
|
||||||
apiVersion: kustomize.config.k8s.io/v1beta1
|
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||||
kind: Kustomization
|
kind: Kustomization
|
||||||
namespace: {{.Namespace}}
|
namespace: {{.Namespace}}
|
||||||
|
|
@ -231,7 +240,11 @@ patchesJson6902:
|
||||||
images:
|
images:
|
||||||
{{- range $i, $component := .Components }}
|
{{- range $i, $component := .Components }}
|
||||||
- name: fluxcd/{{$component}}
|
- name: fluxcd/{{$component}}
|
||||||
|
{{- if eq $arch "amd64" }}
|
||||||
newName: {{$registry}}/{{$component}}
|
newName: {{$registry}}/{{$component}}
|
||||||
|
{{- else }}
|
||||||
|
newName: {{$registry}}/{{$component}}-{{$arch}}
|
||||||
|
{{- end }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
`
|
`
|
||||||
|
|
@ -253,7 +266,7 @@ spec:
|
||||||
template:
|
template:
|
||||||
spec:
|
spec:
|
||||||
nodeSelector:
|
nodeSelector:
|
||||||
kubernetes.io/arch: amd64
|
kubernetes.io/arch: {{.Arch}}
|
||||||
kubernetes.io/os: linux
|
kubernetes.io/os: linux
|
||||||
{{- if .ImagePullSecret }}
|
{{- if .ImagePullSecret }}
|
||||||
imagePullSecrets:
|
imagePullSecrets:
|
||||||
|
|
@ -295,7 +308,7 @@ func downloadManifests(version string, tmpDir string) error {
|
||||||
return nil
|
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 := ""
|
eventsAddr := ""
|
||||||
if utils.containsItemString(components, defaultNotification) {
|
if utils.containsItemString(components, defaultNotification) {
|
||||||
eventsAddr = fmt.Sprintf("http://%s/", defaultNotification)
|
eventsAddr = fmt.Sprintf("http://%s/", defaultNotification)
|
||||||
|
|
@ -308,6 +321,7 @@ func genInstallManifests(version string, namespace string, components []string,
|
||||||
EventsAddr string
|
EventsAddr string
|
||||||
Registry string
|
Registry string
|
||||||
ImagePullSecret string
|
ImagePullSecret string
|
||||||
|
Arch string
|
||||||
}{
|
}{
|
||||||
Version: version,
|
Version: version,
|
||||||
Namespace: namespace,
|
Namespace: namespace,
|
||||||
|
|
@ -315,6 +329,7 @@ func genInstallManifests(version string, namespace string, components []string,
|
||||||
EventsAddr: eventsAddr,
|
EventsAddr: eventsAddr,
|
||||||
Registry: registry,
|
Registry: registry,
|
||||||
ImagePullSecret: imagePullSecret,
|
ImagePullSecret: imagePullSecret,
|
||||||
|
Arch: arch,
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := downloadManifests(version, tmpDir); err != nil {
|
if err := downloadManifests(version, tmpDir); err != nil {
|
||||||
|
|
|
||||||
|
|
@ -108,6 +108,7 @@ var (
|
||||||
defaultVersion = "latest"
|
defaultVersion = "latest"
|
||||||
defaultNamespace = "gitops-system"
|
defaultNamespace = "gitops-system"
|
||||||
defaultNotification = "notification-controller"
|
defaultNotification = "notification-controller"
|
||||||
|
supportedArch = []string{"arm64", "amd64"}
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ The bootstrap sub-commands bootstrap the toolkit components on the targeted Git
|
||||||
### Options
|
### 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])
|
--components strings list of components, accepts comma-separated values (default [source-controller,kustomize-controller,helm-controller,notification-controller])
|
||||||
-h, --help help for bootstrap
|
-h, --help help for bootstrap
|
||||||
--image-pull-secret string Kubernetes secret name used for pulling the toolkit images from a private registry
|
--image-pull-secret string Kubernetes secret name used for pulling the toolkit images from a private registry
|
||||||
|
|
|
||||||
|
|
@ -54,6 +54,7 @@ gotk bootstrap github [flags]
|
||||||
### Options inherited from parent commands
|
### 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])
|
--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
|
--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")
|
--kubeconfig string path to the kubeconfig file (default "~/.kube/config")
|
||||||
|
|
|
||||||
|
|
@ -51,6 +51,7 @@ gotk bootstrap gitlab [flags]
|
||||||
### Options inherited from parent commands
|
### 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])
|
--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
|
--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")
|
--kubeconfig string path to the kubeconfig file (default "~/.kube/config")
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,7 @@ gotk install [flags]
|
||||||
### Options
|
### 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])
|
--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
|
--dry-run only print the object that would be applied
|
||||||
--export write the install manifests to stdout and exit
|
--export write the install manifests to stdout and exit
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue