Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use different name of the kustomization.yaml

For CI/CD purposes, the project is maintaining 2 kustomization.yaml files

  1. Regular deployments - kustomization_deploy.yaml
  2. Rollback deployment - kustomization_rollback.yaml

To run kustomize build, a file with the name "kustomization.yaml" is required in the current directory. If the project wants to use kustomization_rollback.yaml and NOT kustomization.yaml, how is this possible? Does kustomize accept file name as an argument? Docs do not specify anything on this.

like image 648
Girish Avatar asked Oct 14 '22 23:10

Girish


1 Answers

Currently there is no possibility to change the behavior of kustomize to support other file names (by using precompiled binaries) than:

  • kustomization.yaml
  • kustomization.yml
  • Kustomization

All of the below cases will produce the same error output:

  • kubectl kustomize dir/
  • kubectl apply -k dir/
  • kustomize build dir/
Error: unable to find one of 'kustomization.yaml', 'kustomization.yml' or 'Kustomization' in directory 'FULL_PATH/dir'

Depending on the CI/CD platform/solution/tool you should try other way around like for example:

  • split the Deployment into 2 directories kustomization_deploy/kustomization_rollback with kustomization.yaml

As a side note!

File names that kustomize uses are placed in the:

  • /kubernetes/vendor/sigs.k8s.io/kustomize/pkg/constants/constants.go
// Package constants holds global constants for the kustomize tool.
package constants

// KustomizationFileNames is a list of filenames that can be recognized and consumbed
// by Kustomize.
// In each directory, Kustomize searches for file with the name in this list.
// Only one match is allowed.
var KustomizationFileNames = []string{
  "kustomization.yaml",
  "kustomization.yml",
  "Kustomization",
}

The logic behind choosing the Kustomization file is placed in:

  • /kubernetes/vendor/sigs.k8s.io/kustomize/pkg/target/kusttarget.go

Additional reference:

  • Github.com: Kubernetes-sigs: Kustomize
  • Kubernetes.io: Docs: Tasks: Manage kubernetes objects: Kustomization
like image 114
Dawid Kruk Avatar answered Oct 19 '22 00:10

Dawid Kruk