Skip to content
Snippets Groups Projects
Commit 3ddda697 authored by Oscar Tovar's avatar Oscar Tovar :three:
Browse files

Merge branch 'agent-bootstrap-helm-release-values' into 'main'

feat(agent bootstrap): support specifying Agent Helm Chart values

See merge request !1728



Merged-by: default avatarOscar Tovar <otovar@gitlab.com>
Approved-by: default avatarVitali Tatarintev <vtatarintev@gitlab.com>
Approved-by: default avatarOscar Tovar <otovar@gitlab.com>
Reviewed-by: Viktor Nagy  (GitLab)'s avatarViktor Nagy (GitLab) <vnagy@gitlab.com>
Reviewed-by: default avatarOscar Tovar <otovar@gitlab.com>
Co-authored-by: Timo Furrer's avatarTimo Furrer <tfurrer@gitlab.com>
parents 2db471ed c1bf7b46
No related branches found
No related tags found
1 merge request!1728feat(agent bootstrap): support specifying Agent Helm Chart values
Pipeline #1500810551 passed with warnings
......@@ -41,7 +41,7 @@ type KubectlWrapper interface {
type (
APIFactory func(*gitlab.Client, any) API
KubectlWrapperFactory func(Cmd, string, string, string) KubectlWrapper
FluxWrapperFactory func(Cmd, string, string, string, string, string, string, string, string, string, string, string, string) FluxWrapper
FluxWrapperFactory func(Cmd, string, string, string, string, string, string, string, string, string, []string, []string, string, string, string) FluxWrapper
CmdFactory func(io.Writer, io.Writer, []string) Cmd
)
......@@ -103,6 +103,12 @@ glab cluster agent bootstrap my-agent --create-environment=false
# Bootstrap "my-agent" and configure an environment with custom name and Kubernetes namespace
glab cluster agent bootstrap my-agent --environment-name production --environment-namespace default
# Bootstrap "my-agent" and pass additional GitLab Helm Chart values from a local file
glab cluster agent bootstrap my-agent --helm-release-values values.yaml
# Bootstrap "my-agent" and pass additional GitLab Helm Chart values from a Kubernetes ConfigMap
glab cluster agent bootstrap my-agent --helm-release-values-from ConfigMap/agent-config
`,
Aliases: []string{"bs"},
Args: cobra.ExactArgs(1),
......@@ -173,6 +179,14 @@ glab cluster agent bootstrap my-agent --environment-name production --environmen
if err != nil {
return err
}
helmReleaseValues, err := cmd.Flags().GetStringSlice("helm-release-values")
if err != nil {
return err
}
helmReleaseValuesFrom, err := cmd.Flags().GetStringSlice("helm-release-values-from")
if err != nil {
return err
}
gitlabAgentTokenSecretName, err := cmd.Flags().GetString("gitlab-agent-token-secret-name")
if err != nil {
......@@ -245,6 +259,7 @@ glab cluster agent bootstrap my-agent --environment-name production --environmen
c, fluxBinaryName, manifestPath,
helmRepositoryName, helmRepositoryNamespace, helmRepositoryFilepath,
helmReleaseName, helmReleaseNamespace, helmReleaseFilepath, helmReleaseTargetNamespace,
helmReleaseValues, helmReleaseValuesFrom,
fluxSourceType, fluxSourceNamespace, fluxSourceName,
),
noReconcile: noReconcile,
......@@ -265,6 +280,8 @@ glab cluster agent bootstrap my-agent --environment-name production --environmen
agentBootstrapCmd.Flags().String("helm-release-namespace", "flux-system", "Namespace of the Flux HelmRelease manifest.")
agentBootstrapCmd.Flags().String("helm-release-filepath", "gitlab-agent-helm-release.yaml", "Filepath within the GitLab Agent project to commit the Flux HelmRelease to.")
agentBootstrapCmd.Flags().String("helm-release-target-namespace", "gitlab-agent", "Namespace of the GitLab Agent deployment.")
agentBootstrapCmd.Flags().StringSlice("helm-release-values", nil, "Local path to values.yaml files")
agentBootstrapCmd.Flags().StringSlice("helm-release-values-from", nil, "Kubernetes object reference that contains the values.yaml data key in the format '<kind>/<name>', where kind must be one of: (Secret,ConfigMap)")
agentBootstrapCmd.Flags().String("gitlab-agent-token-secret-name", "gitlab-agent-token", "Name of the Secret where the token for the GitLab Agent is stored. The helm-release-target-namespace is implied for the namespace of the Secret.")
......
......@@ -853,7 +853,9 @@ func setupCmdExec(t *testing.T) (execFunc, *MockAPI, *MockWriter, *MockWriter, *
func() error { return nil },
func(*gitlab.Client, any) API { return mockAPI },
func(_ Cmd, _, _, _ string) KubectlWrapper { return mockKubectlWrapper },
func(_ Cmd, _, _, _, _, _, _, _, _, _, _, _, _ string) FluxWrapper { return mockFluxWrapper },
func(_ Cmd, _, _, _, _, _, _, _, _, _ string, _, _ []string, _, _, _ string) FluxWrapper {
return mockFluxWrapper
},
func(_, _ io.Writer, _ []string) Cmd { return mockCmd },
)
......
......@@ -25,6 +25,8 @@ func NewLocalFluxWrapper(
helmReleaseNamespace string,
helmReleaseFilepath string,
helmReleaseTargetNamespace string,
helmReleaseValues []string,
helmReleaseValuesFrom []string,
fluxSourceType string,
fluxSourceNamespace string,
fluxSourceName string,
......@@ -40,6 +42,8 @@ func NewLocalFluxWrapper(
helmReleaseNamespace: helmReleaseNamespace,
helmReleaseFilepath: helmReleaseFilepath,
helmReleaseTargetNamespace: helmReleaseTargetNamespace,
helmReleaseValues: helmReleaseValues,
helmReleaseValuesFrom: helmReleaseValuesFrom,
fluxSourceType: fluxSourceType,
fluxSourceNamespace: fluxSourceNamespace,
fluxSourceName: fluxSourceName,
......@@ -59,6 +63,8 @@ type localFluxWrapper struct {
helmReleaseNamespace string
helmReleaseFilepath string
helmReleaseTargetNamespace string
helmReleaseValues []string
helmReleaseValuesFrom []string
fluxSourceType string
fluxSourceNamespace string
fluxSourceName string
......@@ -114,8 +120,7 @@ func (f *localFluxWrapper) createHelmReleaseManifest(kasAddress string) (file, e
return file{}, err
}
helmReleaseYAML, err := f.cmd.RunWithOutput(
f.binary,
args := []string{
"create",
"helmrelease",
f.helmReleaseName,
......@@ -127,6 +132,18 @@ func (f *localFluxWrapper) createHelmReleaseManifest(kasAddress string) (file, e
"--chart=gitlab-agent",
fmt.Sprintf("--release-name=%s", f.helmReleaseName),
fmt.Sprintf("--values=%s", valuesFile.Name()),
}
for _, v := range f.helmReleaseValues {
args = append(args, fmt.Sprintf("--values=%s", v))
}
for _, v := range f.helmReleaseValuesFrom {
args = append(args, fmt.Sprintf("--values-from=%s", v))
}
helmReleaseYAML, err := f.cmd.RunWithOutput(
f.binary,
args...,
)
if err != nil {
return file{}, err
......
......@@ -52,7 +52,7 @@ func TestFlux_createHelmReReleaseManifest(t *testing.T) {
"flux", "create", "helmrelease", "helm-release-name", "--export",
"-n=helm-release-namespace", "--target-namespace=helm-release-target-namespace",
"--create-target-namespace=true", "--source=HelmRepository/helm-repository-name.helm-repository-namespace",
"--chart=gitlab-agent", "--release-name=helm-release-name", StartsWith("--values=")).
"--chart=gitlab-agent", "--release-name=helm-release-name", StartsWith("--values="), "--values=helm-release-values-1", "--values=helm-release-values-2", "--values-from=helm-release-values-from-1").
Return([]byte("content"), nil)
actualFile, err := f.createHelmReleaseManifest("wss://kas.gitlab.example.com")
......@@ -71,7 +71,7 @@ func TestFlux_createHelmReReleaseManifest_Failure(t *testing.T) {
"flux", "create", "helmrelease", "helm-release-name", "--export",
"-n=helm-release-namespace", "--target-namespace=helm-release-target-namespace",
"--create-target-namespace=true", "--source=HelmRepository/helm-repository-name.helm-repository-namespace",
"--chart=gitlab-agent", "--release-name=helm-release-name", StartsWith("--values=")).
"--chart=gitlab-agent", "--release-name=helm-release-name", StartsWith("--values="), "--values=helm-release-values-1", "--values=helm-release-values-2", "--values-from=helm-release-values-from-1").
Return([]byte(""), errors.New("test"))
actualFile, err := f.createHelmReleaseManifest("wss://kas.gitlab.example.com")
......@@ -138,6 +138,7 @@ func setupFlux(t *testing.T) (*MockCmd, FluxWrapper) {
"flux", "manifest-path",
"helm-repository-name", "helm-repository-namespace", "helm-repository-filepath",
"helm-release-name", "helm-release-namespace", "helm-release-filepath", "helm-release-target-namespace",
[]string{"helm-release-values-1", "helm-release-values-2"}, []string{"helm-release-values-from-1"},
"flux-source-type", "flux-source-namespace", "flux-source-name",
)
fHack := f.(*localFluxWrapper)
......
......@@ -66,6 +66,12 @@ glab cluster agent bootstrap my-agent --create-environment=false
# Bootstrap "my-agent" and configure an environment with custom name and Kubernetes namespace
glab cluster agent bootstrap my-agent --environment-name production --environment-namespace default
# Bootstrap "my-agent" and pass additional GitLab Helm Chart values from a local file
glab cluster agent bootstrap my-agent --helm-release-values values.yaml
# Bootstrap "my-agent" and pass additional GitLab Helm Chart values from a Kubernetes ConfigMap
glab cluster agent bootstrap my-agent --helm-release-values-from ConfigMap/agent-config
```
## Options
......@@ -83,6 +89,8 @@ glab cluster agent bootstrap my-agent --environment-name production --environmen
--helm-release-name string Name of the Flux HelmRelease manifest. (default "gitlab-agent")
--helm-release-namespace string Namespace of the Flux HelmRelease manifest. (default "flux-system")
--helm-release-target-namespace string Namespace of the GitLab Agent deployment. (default "gitlab-agent")
--helm-release-values strings Local path to values.yaml files
--helm-release-values-from strings Kubernetes object reference that contains the values.yaml data key in the format '<kind>/<name>', where kind must be one of: (Secret,ConfigMap)
--helm-repository-filepath string Filepath within the GitLab Agent project to commit the Flux HelmRepository to. (default "gitlab-helm-repository.yaml")
--helm-repository-name string Name of the Flux HelmRepository manifest. (default "gitlab")
--helm-repository-namespace string Namespace of the Flux HelmRepository manifest. (default "flux-system")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment