Skip to content

Commit

Permalink
Upgrade to kustomize v4
Browse files Browse the repository at this point in the history
- Upgrade sigs.k8s.io/kustomize/api from v0.7.4 to v0.8.9
- Upgrade sigs.k8s.io/cli-utils from v0.22.4 to v0.25.0
- Pin sigs.k8s.io/kustomize/kyaml to v0.10.17 (cli-utils compat)
- Pin k8s.io/kube-openapi v0.0.0-20201113171705-d219536bb9fd (cli-utils compat)

Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
  • Loading branch information
stefanprodan committed May 11, 2021
1 parent 9061419 commit fff3310
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 172 deletions.
27 changes: 11 additions & 16 deletions controllers/kustomization_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ import (

"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/kustomize/api/filesys"
"sigs.k8s.io/kustomize/api/k8sdeps/kunstruct"
"sigs.k8s.io/kustomize/api/konfig"
"sigs.k8s.io/kustomize/api/krusty"
"sigs.k8s.io/kustomize/api/provider"
"sigs.k8s.io/kustomize/api/resmap"
kustypes "sigs.k8s.io/kustomize/api/types"
"sigs.k8s.io/yaml"
Expand Down Expand Up @@ -162,7 +162,8 @@ func (kg *KustomizeGenerator) generateKustomization(dirPath string) error {

scan := func(base string) ([]string, error) {
var paths []string
uf := kunstruct.NewKunstructuredFactoryImpl()
pvd := provider.NewDefaultDepProvider()
rf := pvd.GetResourceFactory()
err := fs.Walk(base, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
Expand Down Expand Up @@ -192,7 +193,7 @@ func (kg *KustomizeGenerator) generateKustomization(dirPath string) error {
return err
}

if _, err := uf.SliceFromBytes(fContents); err != nil {
if _, err := rf.SliceFromBytes(fContents); err != nil {
return fmt.Errorf("failed to decode Kubernetes YAML from %s: %w", path, err)
}
paths = append(paths, path)
Expand Down Expand Up @@ -333,24 +334,18 @@ func adaptSelector(selector *kustomize.Selector) (output *kustypes.Selector) {
}

// buildKustomization wraps krusty.MakeKustomizer with the following settings:
// - disable kyaml due to critical bugs like:
// - https://github.com/kubernetes-sigs/kustomize/issues/3446
// - https://github.com/kubernetes-sigs/kustomize/issues/3480
// - reorder the resources just before output (Namespaces and Cluster roles/role bindings first, CRDs before CRs, Webhooks last)
// - load files from outside the kustomization.yaml root
// - disable plugins except for the builtin ones
// - prohibit changes to resourceIds, patch name/kind don't overwrite target name/kind
func buildKustomization(fs filesys.FileSystem, dirPath string) (resmap.ResMap, error) {
buildOptions := &krusty.Options{
UseKyaml: false,
DoLegacyResourceSort: true,
LoadRestrictions: kustypes.LoadRestrictionsNone,
AddManagedbyLabel: false,
DoPrune: false,
PluginConfig: konfig.DisabledPluginConfig(),
AllowResourceIdChanges: false,
DoLegacyResourceSort: true,
LoadRestrictions: kustypes.LoadRestrictionsNone,
AddManagedbyLabel: false,
DoPrune: false,
PluginConfig: kustypes.DisabledPluginConfig(),
}

k := krusty.MakeKustomizer(fs, buildOptions)
return k.Run(dirPath)
k := krusty.MakeKustomizer(buildOptions)
return k.Run(fs, dirPath)
}
13 changes: 10 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ require (
github.com/fluxcd/pkg/untar v0.0.5
github.com/fluxcd/source-controller/api v0.12.1
github.com/go-logr/logr v0.3.0
github.com/hashicorp/go-multierror v1.1.0 // indirect
github.com/hashicorp/go-retryablehttp v0.6.8
github.com/howeyc/gopass v0.0.0-20170109162249-bf9dde6d0d2c
github.com/imdario/mergo v0.3.12 // indirect
github.com/mattn/go-colorable v0.1.4 // indirect
github.com/onsi/ginkgo v1.14.2
github.com/onsi/gomega v1.10.2
github.com/spf13/pflag v1.0.5
Expand All @@ -32,10 +34,15 @@ require (
k8s.io/api v0.20.4
k8s.io/apiextensions-apiserver v0.20.4
k8s.io/apimachinery v0.20.4
k8s.io/cli-runtime v0.20.4 // indirect
k8s.io/client-go v0.20.4
sigs.k8s.io/cli-utils v0.22.4
sigs.k8s.io/cli-utils v0.25.0
sigs.k8s.io/controller-runtime v0.8.3
sigs.k8s.io/kustomize/api v0.7.4
sigs.k8s.io/kustomize/api v0.8.9
sigs.k8s.io/yaml v1.2.0
)

// pin kube-openapi and kyaml due to incompatibility with sigs.k8s.io/cli-utils v0.25.0
replace (
k8s.io/kube-openapi => k8s.io/kube-openapi v0.0.0-20201113171705-d219536bb9fd
sigs.k8s.io/kustomize/kyaml => sigs.k8s.io/kustomize/kyaml v0.10.17
)
Loading

0 comments on commit fff3310

Please sign in to comment.