Skip to content

Commit 195304f

Browse files
committed
simplify without-kustomize tag
1 parent 074a218 commit 195304f

File tree

4 files changed

+12
-44
lines changed

4 files changed

+12
-44
lines changed

pkg/patterns/declarative/kustomize/disabled.go

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,12 @@ package kustomize
55

66
import (
77
"context"
8+
"fmt"
89

9-
"sigs.k8s.io/controller-runtime/pkg/log"
1010
"sigs.k8s.io/kustomize/kyaml/filesys"
1111
)
1212

13-
func init() {
14-
Kustomize = &SkipKustomize{}
15-
}
16-
17-
var _ Kustomizer = &SkipKustomize{}
18-
19-
// NoopKustomize ignore the `kustomization.yaml` file and won't run `kustomize build`.
20-
type SkipKustomize struct{}
21-
22-
// Run is a no-op
23-
func (k *SkipKustomize) Run(ctx context.Context, _ filesys.FileSystem, _ string) ([]byte, error) {
24-
log := log.FromContext(ctx)
25-
log.WithValues("kustomizer", "SkipKustomize").Info("skip running kustomize")
26-
return nil, nil
13+
// Run ignore the `kustomization.yaml` file and won't run `kustomize build`.
14+
func Run(_ context.Context, _ filesys.FileSystem, _ string) ([]byte, error) {
15+
return nil, fmt.Errorf("kustomize support is not compiled in (built with tag `without_kustomize`)")
2716
}

pkg/patterns/declarative/kustomize/enabled.go

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
//go:build !without_kustomize
2+
// +build !without_kustomize
3+
14
package kustomize
25

36
import (
@@ -9,19 +12,11 @@ import (
912
"sigs.k8s.io/kustomize/kyaml/filesys"
1013
)
1114

12-
func init() {
13-
Kustomize = &EnabledKustomize{}
14-
}
15-
16-
var _ Kustomizer = &EnabledKustomize{}
17-
18-
// EnabledKustomize runs kustomize build. It requires kustomize/api v0.12.1 and above
19-
type EnabledKustomize struct{}
20-
21-
// Run calls the kustomize/api library to run `kustomize build`.
22-
func (k *EnabledKustomize) Run(ctx context.Context, fs filesys.FileSystem, manifestPath string) ([]byte, error) {
15+
// Run calls the kustomize/api library to run `kustomize build`. This method is differentiated by go build
16+
// tag `without-kustomize`
17+
func Run(ctx context.Context, fs filesys.FileSystem, manifestPath string) ([]byte, error) {
2318
log := log.FromContext(ctx)
24-
log.WithValues("kustomizer", "EnabledKustomize").Info("running kustomize")
19+
log.WithValues("manifestPath", manifestPath).Info("running kustomize")
2520
// run kustomize to create final manifest
2621
opts := krusty.MakeDefaultOptions()
2722
kustomizer := krusty.MakeKustomizer(opts)

pkg/patterns/declarative/kustomize/kustomizer.go

Lines changed: 0 additions & 16 deletions
This file was deleted.

pkg/patterns/declarative/reconciler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ func (r *Reconciler) BuildDeploymentObjectsWithFs(ctx context.Context, name type
390390
// Here, the manifest is built using Kustomize and then replaces the Object items with the created manifest
391391
if r.IsKustomizeOptionUsed() {
392392
// run kustomize to create final manifest
393-
manifestYaml, err := kustomize.Kustomize.Run(ctx, fs, manifestObjects.Path)
393+
manifestYaml, err := kustomize.Run(ctx, fs, manifestObjects.Path)
394394
if err != nil {
395395
log.Error(err, "run kustomize build")
396396
return nil, fmt.Errorf("error running kustomize: %v", err)

0 commit comments

Comments
 (0)