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

Allow using kubectl built-in kustomize if separate kustomize binary is missing #63

Open
reegnz opened this issue Sep 18, 2023 · 4 comments

Comments

@reegnz
Copy link

reegnz commented Sep 18, 2023

You can run kustomize commands with kubectl like this:

kubectl kustomize ...

Either fall back automatically to the kubectl built-in kustomize, or allow the user to select it.

@reegnz
Copy link
Author

reegnz commented Sep 18, 2023

The feature to add a custom binary recently got added(#62), maybe it can be used to solve this problem.

@reegnz
Copy link
Author

reegnz commented Sep 18, 2023

As far as I can tell I could just feed kubectl kustomize as the kustomizeBinary, and it should work, the runner implementation handles args passed in kustomizeBinary by splitting and treating args correctly:

chartify/runner.go

Lines 128 to 138 in a67147a

func (r *Runner) runBytes(dir, cmd string, args ...string) ([]byte, error) {
nameArgs := strings.Split(cmd, " ")
name := nameArgs[0]
if len(nameArgs) > 2 {
a := append([]string{}, nameArgs[1:]...)
a = append(a, args...)
args = a
}

I'm using chartify through helmfile, so I'll wait until this feature lands in helmfile to verify.

@reegnz reegnz changed the title Allow using kustomize built into kubectl if kustomize binary is missing Allow using kubectl built-in kustomize if separate kustomize binary is missing Sep 18, 2023
@reegnz
Copy link
Author

reegnz commented Apr 15, 2024

Managed to get around testing this.

So problem is that when I pass kustomizeBinary: kubectl kustomize to helmfile, I get this:

 kubectl build /var/folders/qn/hzhf777s1vx9lr4xc8zj1f_h0000gn/T/chartify3414166477/actions/actions-runner-controller --output /var/folders/qn/hzhf777s1vx9lr4xc8zj1f_h0000gn/T/chartify3414166477/actions/actions-runner-controller/all.patched.yaml --enable_alpha_plugins

OUTPUT:
  error: unknown command "build" for "kubectl"]

I did manage to write a kustomize-shim script to make kubectl kustomize work with helmfile:

#!/usr/bin/env bash

if [ "$1" == "version" ]; then
  kubectl version --client --short 2>/dev/null | awk '/Kustomize/{print $NF}'
  exit
elif [ "$1" == "build" ]; then
  shift
  exec kubectl kustomize $@
else
  echo "Could not shim kustomize: $@" >&2
  exit 99
fi

Then in helmfile.yaml:

kustomizeBinary: kustomize-shim

@reegnz
Copy link
Author

reegnz commented Apr 22, 2024

Turns out the above shim doesn't always work because chartify also runs kustomize edit in some cases, but kubectl kustomize does not support edit...

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

No branches or pull requests

1 participant