From 998b763cf955ff47451a5ada64de8be223a9bee8 Mon Sep 17 00:00:00 2001 From: Stefan Prodan <stefan.prodan@gmail.com> Date: Thu, 2 Jun 2022 16:10:31 +0300 Subject: [PATCH] Add `--kubeconfig-secret-ref` to `flux create ks|hr` Allow specifying the name of the Kubernetes Secret that contains a key with the kubeconfig file for connecting to a remote cluster. Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com> --- cmd/flux/.create_helmrelease.go.swp | Bin 16384 -> 0 bytes cmd/flux/create_helmrelease.go | 36 +++++++++++------- cmd/flux/create_kustomization.go | 57 ++++++++++++++++------------ 3 files changed, 56 insertions(+), 37 deletions(-) delete mode 100644 cmd/flux/.create_helmrelease.go.swp diff --git a/cmd/flux/.create_helmrelease.go.swp b/cmd/flux/.create_helmrelease.go.swp deleted file mode 100644 index d42c707c4f43f19c29f11e07724beb5f80e304ef..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 16384 zcmeI2U5q4E702%aq78yZj1N5Mr3ss!O?TDIEJhsch1p>ShMf<Xp4rVhY}lIW+ug;~ zM^m?|dzx{<7{iOk7=6J6MG{bgPm&0UM8F3gj7l&PjR`2e2>69xNEFHXKes-n`eSEU z3?VVq+22lA-COsbd(OG%o_o7C#*fY~@~gB-hR+8XD_(!`#`s_E+xKRTG3hyhXSOWQ z?TO8<@CDTw@u|i2WM$DX4}0Eb<tE?LY|k|8zS?&VHK;c|UHYcpw1QT+p_!heH|%iB ztgAnhy6HsUbki3`AZ~35+wp}h3@Nmx*VlM{k!v8=z#ba7h#j1q7^g~?7cb+Nd}wWt z`gw7#fm{Q*267GL8pt(}YarJ^u7O+w|4$kS+UK&nFrahdLCN^<zJb4|<Ikt#`@ul@ zx$*Vw@!w|#%HzxYPp*Mn1Gxrr4dfcgHIQo{*Fdg;Tm!iVat-7f$TjdTXuzm5b}{<> zCvEug`+u_kfAa&3y#SsE_kwkB5KMw|!8zawJop)K5WIR3W6y%0f}emV!4u$n;9>AJ z@D=by@C9I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%H&eqHp9J(Y6Wq`o0!dV-#j@U4kNXNqx% zRzZ)%!A4qYbPyO7l+?K+t&>gCA&nI0=h)tul)~F3*jFuJ(IpKiSr(3A8?+j!wv^mE zjLloqSD^t5{h$Q~)Y!%kG{LO;nWGf_+L0MxsZS}80{V^upE7m)>j=&(l>41hQI+O= z-*i`1qr=NNoC&KnlY&Fxh~?IItw|NAX2vVk`k)<EKe$k9SO(TlP&r~$ba#amhdr*? zM!bN$nTH1@si|M5u-GGgC>9aEqj6-O$aY6-Vc*d}XF|KNw!E~xVsxiCZKm<%6xxWE zm?WKW0&SL(2>6g=__Af#<m-_>c*DTH4NAD8i<wMu98VAVbRlj#^=7)(7Nf>WQA>+P zn+zLuo!)}T>G^}UDDVph>dBo)%1Z3y+34Xk56TE0x+6p<?IRTR4WW~cA{hpJRf)Tn zG*P0<!#y0{mHB@9PTdct0|hl^l#s7G#-=DaMthxh?QZjgItppvN2cvlYRqSr8#4l@ z4Jx?A3de4pY!;mc?=5{MuT&Dna>olR9j<9~=)LMuqa~ai8hc1YQ9En@x2D9b7}QDX z37%A${T#fg)FJ1g7<y}&cSvtIdBTB9#+$SLPp9-MVcBt(y;MymwS}AAZw$6LhM!8u HX(Ig>3(~gr diff --git a/cmd/flux/create_helmrelease.go b/cmd/flux/create_helmrelease.go index 5a5f2c84..b4fdcdf1 100644 --- a/cmd/flux/create_helmrelease.go +++ b/cmd/flux/create_helmrelease.go @@ -109,19 +109,20 @@ var createHelmReleaseCmd = &cobra.Command{ } type helmReleaseFlags struct { - name string - source flags.HelmChartSource - dependsOn []string - chart string - chartVersion string - targetNamespace string - createNamespace bool - valuesFiles []string - valuesFrom flags.HelmReleaseValuesFrom - saName string - crds flags.CRDsPolicy - reconcileStrategy string - chartInterval time.Duration + name string + source flags.HelmChartSource + dependsOn []string + chart string + chartVersion string + targetNamespace string + createNamespace bool + valuesFiles []string + valuesFrom flags.HelmReleaseValuesFrom + saName string + crds flags.CRDsPolicy + reconcileStrategy string + chartInterval time.Duration + kubeConfigSecretRef string } var helmReleaseArgs helmReleaseFlags @@ -140,6 +141,7 @@ func init() { createHelmReleaseCmd.Flags().StringSliceVar(&helmReleaseArgs.valuesFiles, "values", nil, "local path to values.yaml files, also accepts comma-separated values") createHelmReleaseCmd.Flags().Var(&helmReleaseArgs.valuesFrom, "values-from", helmReleaseArgs.valuesFrom.Description()) createHelmReleaseCmd.Flags().Var(&helmReleaseArgs.crds, "crds", helmReleaseArgs.crds.Description()) + createHelmReleaseCmd.Flags().StringVar(&helmReleaseArgs.kubeConfigSecretRef, "kubeconfig-secret-ref", "", "the name of the Kubernetes Secret that contains a key with the kubeconfig file for connecting to a remote cluster") createCmd.AddCommand(createHelmReleaseCmd) } @@ -194,6 +196,14 @@ func createHelmReleaseCmdRun(cmd *cobra.Command, args []string) error { }, } + if helmReleaseArgs.kubeConfigSecretRef != "" { + helmRelease.Spec.KubeConfig = &helmv2.KubeConfig{ + SecretRef: meta.SecretKeyReference{ + Name: helmReleaseArgs.kubeConfigSecretRef, + }, + } + } + if helmReleaseArgs.chartInterval != 0 { helmRelease.Spec.Chart.Spec.Interval = &metav1.Duration{ Duration: helmReleaseArgs.chartInterval, diff --git a/cmd/flux/create_kustomization.go b/cmd/flux/create_kustomization.go index ef55c23c..f808a99f 100644 --- a/cmd/flux/create_kustomization.go +++ b/cmd/flux/create_kustomization.go @@ -42,22 +42,21 @@ var createKsCmd = &cobra.Command{ Use: "kustomization [name]", Aliases: []string{"ks"}, Short: "Create or update a Kustomization resource", - Long: "The kustomization source create command generates a Kustomize resource for a given source.", + Long: "The create command generates a Kustomization resource for a given source.", Example: ` # Create a Kustomization resource from a source at a given path - flux create kustomization contour \ - --source=GitRepository/contour \ - --path="./examples/contour/" \ + flux create kustomization kyverno \ + --source=GitRepository/kyverno \ + --path="./config/release" \ --prune=true \ - --interval=10m \ - --health-check="Deployment/contour.projectcontour" \ - --health-check="DaemonSet/envoy.projectcontour" \ + --interval=60m \ + --wait=true \ --health-check-timeout=3m # Create a Kustomization resource that depends on the previous one - flux create kustomization webapp \ - --depends-on=contour \ - --source=GitRepository/webapp \ - --path="./deploy/overlays/dev" \ + flux create kustomization kyverno-policies \ + --depends-on=kyverno \ + --source=GitRepository/kyverno-policies \ + --path="./policies/flux" \ --prune=true \ --interval=5m @@ -65,7 +64,7 @@ var createKsCmd = &cobra.Command{ flux create kustomization podinfo \ --namespace=default \ --source=GitRepository/podinfo.flux-system \ - --path="./deploy/overlays/dev" \ + --path="./kustomize" \ --prune=true \ --interval=5m @@ -78,18 +77,19 @@ var createKsCmd = &cobra.Command{ } type kustomizationFlags struct { - source flags.KustomizationSource - path flags.SafeRelativePath - prune bool - dependsOn []string - validation string - healthCheck []string - healthTimeout time.Duration - saName string - decryptionProvider flags.DecryptionProvider - decryptionSecret string - targetNamespace string - wait bool + source flags.KustomizationSource + path flags.SafeRelativePath + prune bool + dependsOn []string + validation string + healthCheck []string + healthTimeout time.Duration + saName string + decryptionProvider flags.DecryptionProvider + decryptionSecret string + targetNamespace string + wait bool + kubeConfigSecretRef string } var kustomizationArgs = NewKustomizationFlags() @@ -107,6 +107,7 @@ func init() { createKsCmd.Flags().Var(&kustomizationArgs.decryptionProvider, "decryption-provider", kustomizationArgs.decryptionProvider.Description()) createKsCmd.Flags().StringVar(&kustomizationArgs.decryptionSecret, "decryption-secret", "", "set the Kubernetes secret name that contains the OpenPGP private keys used for sops decryption") createKsCmd.Flags().StringVar(&kustomizationArgs.targetNamespace, "target-namespace", "", "overrides the namespace of all Kustomization objects reconciled by this Kustomization") + createKsCmd.Flags().StringVar(&kustomizationArgs.kubeConfigSecretRef, "kubeconfig-secret-ref", "", "the name of the Kubernetes Secret that contains a key with the kubeconfig file for connecting to a remote cluster") createKsCmd.Flags().MarkDeprecated("validation", "this arg is no longer used, all resources are validated using server-side apply dry-run") createCmd.AddCommand(createKsCmd) @@ -160,6 +161,14 @@ func createKsCmdRun(cmd *cobra.Command, args []string) error { }, } + if kustomizationArgs.kubeConfigSecretRef != "" { + kustomization.Spec.KubeConfig = &kustomizev1.KubeConfig{ + SecretRef: meta.SecretKeyReference{ + Name: kustomizationArgs.kubeConfigSecretRef, + }, + } + } + if len(kustomizationArgs.healthCheck) > 0 && !kustomizationArgs.wait { healthChecks := make([]meta.NamespacedObjectKindReference, 0) for _, w := range kustomizationArgs.healthCheck { -- GitLab