Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add diffArgs to helmDefaults #1019

Merged
merged 2 commits into from Sep 14, 2023
Merged

Conversation

yktakaha4
Copy link
Contributor

This OSS always helps me. Thank you to all the maintainers.

In my use case, I want to keep diffArgs in helmfile.yaml. (Added in #959)
I think this is useful if you want to specify additional arguments to helm-diff only when using a specific helmfile.yaml.
(It is now possible to version control argument specifications for specific charts)

Please let me know if there is anything else I need to do to fix it.


For example,

$ ls -l helmfile.yaml 
-rw-r--r-- 1 tkhs tkhs 1567 Sep 13 00:03 helmfile.yaml

$ /home/runner/work/helmfile/helmfile/helmfile diff
Adding repo eks https://aws.github.io/eks-charts
"eks" has been added to your repositories

Comparing release=aws-load-balancer-controller, chart=eks/aws-load-balancer-controller
kube-system, aws-load-balancer-tls, Secret (v1) has changed:
  # Source: aws-load-balancer-controller/templates/webhook.yaml
  apiVersion: v1
  kind: Secret
  metadata:
    labels:
      app.kubernetes.io/instance: aws-load-balancer-controller
      app.kubernetes.io/managed-by: Helm
      app.kubernetes.io/name: aws-load-balancer-controller
      app.kubernetes.io/version: v2.4.5
      helm.sh/chart: aws-load-balancer-controller-1.4.6
    name: aws-load-balancer-tls
    namespace: kube-system
  data:
-   ca.crt: '-------- # (1188 bytes)'
-   tls.crt: '-------- # (1428 bytes)'
-   tls.key: '-------- # (1679 bytes)'
+   ca.crt: '++++++++ # (1188 bytes)'
+   tls.crt: '++++++++ # (1428 bytes)'
+   tls.key: '++++++++ # (1675 bytes)'
  type: kubernetes.io/tls
...

kube-system, aws-load-balancer-webhook, MutatingWebhookConfiguration (admissionregistration.k8s.io) has changed:
  # Source: aws-load-balancer-controller/templates/webhook.yaml
  apiVersion: admissionregistration.k8s.io/v1
  kind: MutatingWebhookConfiguration
  metadata:
    name: aws-load-balancer-webhook
    labels:
      helm.sh/chart: aws-load-balancer-controller-1.4.6
      app.kubernetes.io/name: aws-load-balancer-controller
      app.kubernetes.io/instance: aws-load-balancer-controller
      app.kubernetes.io/version: "v2.4.5"
      app.kubernetes.io/managed-by: Helm
  webhooks:
  - clientConfig:
-     caBundle: LS0tLxxxxx
+     caBundle: LS0tLyyyyy

Add helmDefaults.diffArgs to helmfile.yaml

helmDefaults:
  diffArgs:
    - --suppress-secrets
    - --suppress
    - MutatingWebhookConfiguration
    - --suppress
    - ValidatingWebhookConfiguration

Options are set for helm-diff only helmfile diff and helmfile apply .

$ /home/runner/work/helmfile/helmfile/helmfile diff
Adding repo eks https://aws.github.io/eks-charts
"eks" has been added to your repositories

Comparing release=aws-load-balancer-controller, chart=eks/aws-load-balancer-controller
kube-system, aws-load-balancer-tls, Secret (v1) has changed:
+ Changes suppressed on sensitive content of type Secret
kube-system, aws-load-balancer-webhook, MutatingWebhookConfiguration (admissionregistration.k8s.io) has changed:
+ Changes suppressed on sensitive content of type MutatingWebhookConfiguration
kube-system, aws-load-balancer-webhook, ValidatingWebhookConfiguration (admissionregistration.k8s.io) has changed:
+ Changes suppressed on sensitive content of type ValidatingWebhookConfiguration

Other subcommands, such as helmfile template, are not affected.

$ /home/runner/work/helmfile/helmfile/helmfile template | head
Adding repo eks https://aws.github.io/eks-charts
"eks" has been added to your repositories

Templating release=aws-load-balancer-controller, chart=eks/aws-load-balancer-controller
---
# Source: aws-load-balancer-controller/templates/serviceaccount.yaml
apiVersion: v1
kind: ServiceAccount
metadata:
  name: aws-load-balancer-controller
  namespace: kube-system
  labels:
    helm.sh/chart: aws-load-balancer-controller-1.4.6
    app.kubernetes.io/name: aws-load-balancer-controller

Signed-off-by: Yuuki Takahashi <20282867+yktakaha4@users.noreply.github.com>
@@ -83,7 +83,7 @@ func analyzeArgs(am *argMap, args string) {
}
}

func GetArgs(args string, state *state.HelmState) []string {
func GetArgs(args string, state *state.HelmState, withDiffArgs bool) []string {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ yktakaha4 We can make this func more flexible. there will be more args like applyArgs, sync Args. WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yxxhero Thank you for your review.
Should I modify it so that I can get the type of subcommand currently being executed from HelmState , or define a struct like GetArgsOptions ?
I would be happy to hear your opinions on how to make it more maintainable.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yktakaha4 we can try to define a struct like GetArgsOptions.

Copy link
Contributor Author

@yktakaha4 yktakaha4 Sep 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed to use GetArgsOptions.

In the current usage of GetArgs, It seems possible to change the interface to GetArgs(c ApplyConfigProvider, state *state.HelmState, opts *GetArgsOptions) and decide whether to include diffArgs inside GetArgs.
Should I make this change?

helmfile/pkg/app/app.go

Lines 1372 to 1375 in a08b986

// join --args and --diff-args together to one string.
args := strings.Join([]string{c.Args(), c.DiffArgs()}, " ")
argsOpts := &argparser.GetArgsOptions{WithDiffArgs: true}
helm.SetExtraArgs(argparser.GetArgs(args, r.state, argsOpts)...)


Edit: I looked at the code again and realized that making the above changes requires more abstraction to the ConfigProvider, so I'm retracting it.

Signed-off-by: Yuuki Takahashi <20282867+yktakaha4@users.noreply.github.com>
@yxxhero yxxhero merged commit 430a825 into helmfile:main Sep 14, 2023
14 checks passed
xiaomudk pushed a commit to woodcockjosh/helmfile that referenced this pull request Sep 19, 2023
* Add diffArgs to helmDefaults

Signed-off-by: Yuuki Takahashi <20282867+yktakaha4@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants