From 998b763cf955ff47451a5ada64de8be223a9bee8 Mon Sep 17 00:00:00 2001 From: Stefan Prodan 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 --- 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>ShMf69xNEFHXKes-n`eSEU z3?VVq+22lA-COsbd(OG%o_o7C#*fY~@~gB-hR+8XD_(!`#`s_E+xKRTG3hyhXSOWQ z?TO8<@CDTw@u|i2WM$DX4}0Eb zCvEug`+u_kfAa&3y#SsE_kwkB5KMw|!8zawJop)K5WIR3W6y%0f}emV!4u$n;9>AJ z@D=by@C9IiPk;}DSKiOq%itOCIdBUY2m8Q_7c%xZ_!77S^uRQ@1{?yHfWKeB*ss6? z;7ahj0%Jc0kAg3QJHQEW3%C@Vejj7M2Ty~Cz_)=7ZU&zM9|ijW15dvf@`KL<7c2q| zRKTm}V|?HgSO*^m9|Nzwhp~Tvr@({YZg3LZ2nD;D>4m;2lKPxCY@;c)8}OpW4E0e{#jM~O zPNq`YVbE&}PH%OrL~nJ>(bFVNXa;;6s%3?h(4C#)(F-8dY+Q53siUOKsOL&WY_&Z< z;D>nIt6Ofvt0ZrU^bE&7nbhhSb|_?3)1xmM74lo+CX`C5@$>23Xn57ATx+OPx7cangVZe=c+wQ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}LoK8AOvP=quj?GWHZ0#!VN61N zge2rwzCfU(M`$Ua0EUQ4fyNAdwZm7NE!E)}#Kby}_8}&|kW3g5PId|fx}2)2o!pGd zXdrt~GJ`FQEIFO1FX3A`I}9XTv924TYnH}%X~XkuEHji%j8Vh=4|A2~Xw;56?-*{8 zABZwIb!HWtXN*(!v}2t)^o6#mOX%Q+9Xl#>kwpsB`=uskc*YjvhvWO zxqyPVIu&*-!wR%fNwlpD(V5ITajfJexPG+V=`$8481;10TU;{^&T1}-C@#Z{66xu(eWf3KZXP1{)~RdhP-cQ zdaEdQ6Lz2Tjw9+8VtUEgCA&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)9aEqj6-O$aY6-Vc*d}XF|KNw!E~xVsxiCZKm<%6xxWE zm?WKW0&SL(2>6g=__Af#c*DTH4NAD8iWQA>+P zn+zLuo!)}T>G^}UDDVph>dBo)%1Z3y+34Xk56TE0x+6polR9j<9~=)LMuqa~ai8hc1YQ9En@x2D9b7}QDX z37%A${T#fg)FJ1g73(~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 {