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>
This commit is contained in:
Binary file not shown.
@@ -109,19 +109,20 @@ var createHelmReleaseCmd = &cobra.Command{
|
|||||||
}
|
}
|
||||||
|
|
||||||
type helmReleaseFlags struct {
|
type helmReleaseFlags struct {
|
||||||
name string
|
name string
|
||||||
source flags.HelmChartSource
|
source flags.HelmChartSource
|
||||||
dependsOn []string
|
dependsOn []string
|
||||||
chart string
|
chart string
|
||||||
chartVersion string
|
chartVersion string
|
||||||
targetNamespace string
|
targetNamespace string
|
||||||
createNamespace bool
|
createNamespace bool
|
||||||
valuesFiles []string
|
valuesFiles []string
|
||||||
valuesFrom flags.HelmReleaseValuesFrom
|
valuesFrom flags.HelmReleaseValuesFrom
|
||||||
saName string
|
saName string
|
||||||
crds flags.CRDsPolicy
|
crds flags.CRDsPolicy
|
||||||
reconcileStrategy string
|
reconcileStrategy string
|
||||||
chartInterval time.Duration
|
chartInterval time.Duration
|
||||||
|
kubeConfigSecretRef string
|
||||||
}
|
}
|
||||||
|
|
||||||
var helmReleaseArgs helmReleaseFlags
|
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().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.valuesFrom, "values-from", helmReleaseArgs.valuesFrom.Description())
|
||||||
createHelmReleaseCmd.Flags().Var(&helmReleaseArgs.crds, "crds", helmReleaseArgs.crds.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)
|
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 {
|
if helmReleaseArgs.chartInterval != 0 {
|
||||||
helmRelease.Spec.Chart.Spec.Interval = &metav1.Duration{
|
helmRelease.Spec.Chart.Spec.Interval = &metav1.Duration{
|
||||||
Duration: helmReleaseArgs.chartInterval,
|
Duration: helmReleaseArgs.chartInterval,
|
||||||
|
|||||||
@@ -42,22 +42,21 @@ var createKsCmd = &cobra.Command{
|
|||||||
Use: "kustomization [name]",
|
Use: "kustomization [name]",
|
||||||
Aliases: []string{"ks"},
|
Aliases: []string{"ks"},
|
||||||
Short: "Create or update a Kustomization resource",
|
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
|
Example: ` # Create a Kustomization resource from a source at a given path
|
||||||
flux create kustomization contour \
|
flux create kustomization kyverno \
|
||||||
--source=GitRepository/contour \
|
--source=GitRepository/kyverno \
|
||||||
--path="./examples/contour/" \
|
--path="./config/release" \
|
||||||
--prune=true \
|
--prune=true \
|
||||||
--interval=10m \
|
--interval=60m \
|
||||||
--health-check="Deployment/contour.projectcontour" \
|
--wait=true \
|
||||||
--health-check="DaemonSet/envoy.projectcontour" \
|
|
||||||
--health-check-timeout=3m
|
--health-check-timeout=3m
|
||||||
|
|
||||||
# Create a Kustomization resource that depends on the previous one
|
# Create a Kustomization resource that depends on the previous one
|
||||||
flux create kustomization webapp \
|
flux create kustomization kyverno-policies \
|
||||||
--depends-on=contour \
|
--depends-on=kyverno \
|
||||||
--source=GitRepository/webapp \
|
--source=GitRepository/kyverno-policies \
|
||||||
--path="./deploy/overlays/dev" \
|
--path="./policies/flux" \
|
||||||
--prune=true \
|
--prune=true \
|
||||||
--interval=5m
|
--interval=5m
|
||||||
|
|
||||||
@@ -65,7 +64,7 @@ var createKsCmd = &cobra.Command{
|
|||||||
flux create kustomization podinfo \
|
flux create kustomization podinfo \
|
||||||
--namespace=default \
|
--namespace=default \
|
||||||
--source=GitRepository/podinfo.flux-system \
|
--source=GitRepository/podinfo.flux-system \
|
||||||
--path="./deploy/overlays/dev" \
|
--path="./kustomize" \
|
||||||
--prune=true \
|
--prune=true \
|
||||||
--interval=5m
|
--interval=5m
|
||||||
|
|
||||||
@@ -78,18 +77,19 @@ var createKsCmd = &cobra.Command{
|
|||||||
}
|
}
|
||||||
|
|
||||||
type kustomizationFlags struct {
|
type kustomizationFlags struct {
|
||||||
source flags.KustomizationSource
|
source flags.KustomizationSource
|
||||||
path flags.SafeRelativePath
|
path flags.SafeRelativePath
|
||||||
prune bool
|
prune bool
|
||||||
dependsOn []string
|
dependsOn []string
|
||||||
validation string
|
validation string
|
||||||
healthCheck []string
|
healthCheck []string
|
||||||
healthTimeout time.Duration
|
healthTimeout time.Duration
|
||||||
saName string
|
saName string
|
||||||
decryptionProvider flags.DecryptionProvider
|
decryptionProvider flags.DecryptionProvider
|
||||||
decryptionSecret string
|
decryptionSecret string
|
||||||
targetNamespace string
|
targetNamespace string
|
||||||
wait bool
|
wait bool
|
||||||
|
kubeConfigSecretRef string
|
||||||
}
|
}
|
||||||
|
|
||||||
var kustomizationArgs = NewKustomizationFlags()
|
var kustomizationArgs = NewKustomizationFlags()
|
||||||
@@ -107,6 +107,7 @@ func init() {
|
|||||||
createKsCmd.Flags().Var(&kustomizationArgs.decryptionProvider, "decryption-provider", kustomizationArgs.decryptionProvider.Description())
|
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.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.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")
|
createKsCmd.Flags().MarkDeprecated("validation", "this arg is no longer used, all resources are validated using server-side apply dry-run")
|
||||||
|
|
||||||
createCmd.AddCommand(createKsCmd)
|
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 {
|
if len(kustomizationArgs.healthCheck) > 0 && !kustomizationArgs.wait {
|
||||||
healthChecks := make([]meta.NamespacedObjectKindReference, 0)
|
healthChecks := make([]meta.NamespacedObjectKindReference, 0)
|
||||||
for _, w := range kustomizationArgs.healthCheck {
|
for _, w := range kustomizationArgs.healthCheck {
|
||||||
|
|||||||
Reference in New Issue
Block a user