Skip to content

Commit 2953dad

Browse files
committed
add MakeHashTransformer in TransformerFactory; remove hash interface
1 parent 681e2bf commit 2953dad

File tree

16 files changed

+88
-66
lines changed

16 files changed

+88
-66
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
Copyright 2018 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
// Package transformer provides transformer factory
18+
package transformer
19+
20+
import (
21+
"sigs.k8s.io/kustomize/internal/k8sdeps/transformer/hash"
22+
"sigs.k8s.io/kustomize/internal/k8sdeps/transformer/patch"
23+
"sigs.k8s.io/kustomize/pkg/resource"
24+
"sigs.k8s.io/kustomize/pkg/transformers"
25+
)
26+
27+
// factoryImpl makes patch transformer and name hash transformer
28+
type factoryImpl struct{}
29+
30+
// NewFactoryImpl makes a new factoryImpl instance
31+
func NewFactoryImpl() *factoryImpl {
32+
return &factoryImpl{}
33+
}
34+
35+
// MakePatchTransformer makes a new patch transformer
36+
func (p *factoryImpl) MakePatchTransformer(slice []*resource.Resource, rf *resource.Factory) (transformers.Transformer, error) {
37+
return patch.NewPatchTransformer(slice, rf)
38+
}
39+
40+
// MakeHashTransformer makes a new name hash transformer
41+
func (p *factoryImpl) MakeHashTransformer() transformers.Transformer {
42+
return hash.NewNameHashTransformer()
43+
}

internal/k8sdeps/hash.go renamed to internal/k8sdeps/transformer/hash/hash.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package k8sdeps
17+
package hash
1818

1919
import (
2020
"crypto/sha256"

internal/k8sdeps/hash_test.go renamed to internal/k8sdeps/transformer/hash/hash_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,22 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package k8sdeps
17+
package hash
1818

1919
import (
2020
"reflect"
2121
"strings"
2222
"testing"
2323

2424
"k8s.io/api/core/v1"
25+
"sigs.k8s.io/kustomize/pkg/gvk"
2526
)
2627

28+
var service = gvk.Gvk{Version: "v1", Kind: "Service"}
29+
var secret = gvk.Gvk{Version: "v1", Kind: "Secret"}
30+
var cmap = gvk.Gvk{Version: "v1", Kind: "ConfigMap"}
31+
var deploy = gvk.Gvk{Group: "apps", Version: "v1", Kind: "Deployment"}
32+
2733
func TestConfigMapHash(t *testing.T) {
2834
cases := []struct {
2935
desc string

pkg/transformers/namehash.go renamed to internal/k8sdeps/transformer/hash/namehash.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,25 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package transformers
17+
package hash
1818

1919
import (
2020
"fmt"
2121

22-
"sigs.k8s.io/kustomize/pkg/ifc"
2322
"sigs.k8s.io/kustomize/pkg/resmap"
2423
"sigs.k8s.io/kustomize/pkg/resource"
24+
"sigs.k8s.io/kustomize/pkg/transformers"
2525
)
2626

2727
// nameHashTransformer contains the prefix and the path config for each field that
2828
// the name prefix will be applied.
29-
type nameHashTransformer struct {
30-
hash ifc.Hash
31-
}
29+
type nameHashTransformer struct{}
3230

33-
var _ Transformer = &nameHashTransformer{}
31+
var _ transformers.Transformer = &nameHashTransformer{}
3432

3533
// NewNameHashTransformer construct a nameHashTransformer.
36-
func NewNameHashTransformer(h ifc.Hash) Transformer {
37-
return &nameHashTransformer{hash: h}
34+
func NewNameHashTransformer() transformers.Transformer {
35+
return &nameHashTransformer{}
3836
}
3937

4038
// Transform appends hash to configmaps and secrets.
@@ -51,7 +49,7 @@ func (o *nameHashTransformer) Transform(m resmap.ResMap) error {
5149
}
5250

5351
func (o *nameHashTransformer) appendHash(res *resource.Resource) error {
54-
h, err := o.hash.Hash(res.Map())
52+
h, err := NewKustHash().Hash(res.Map())
5553
if err != nil {
5654
return err
5755
}

pkg/transformers/namehash_test.go renamed to internal/k8sdeps/transformer/hash/namehash_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package transformers
17+
package hash
1818

1919
import (
2020
"reflect"
@@ -152,7 +152,7 @@ func TestNameHashTransformer(t *testing.T) {
152152
}).SetBehavior(ifc.BehaviorCreate),
153153
}
154154

155-
tran := NewNameHashTransformer(k8sdeps.NewKustHash())
155+
tran := NewNameHashTransformer()
156156
tran.Transform(objs)
157157

158158
if !reflect.DeepEqual(objs, expected) {

internal/k8sdeps/patch/patch.go renamed to internal/k8sdeps/transformer/patch/patch.go

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,6 @@ import (
3131
"sigs.k8s.io/kustomize/pkg/transformers"
3232
)
3333

34-
// patchTransformerFactory makes patch transformer
35-
type patchTransformerFactory struct{}
36-
37-
// NewPatchTransformerFactory makes a new patchTransformerFactory
38-
func NewPatchTransformerFactory() *patchTransformerFactory {
39-
return &patchTransformerFactory{}
40-
}
41-
42-
// MakePatchTransformer makes a new patch transformer
43-
func (p *patchTransformerFactory) MakePatchTransformer(slice []*resource.Resource, rf *resource.Factory) (transformers.Transformer, error) {
44-
return NewPatchTransformer(slice, rf)
45-
}
46-
4734
// patchTransformer applies patches.
4835
type patchTransformer struct {
4936
patches []*resource.Resource

kustomize.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121

2222
"github.com/golang/glog"
2323
"sigs.k8s.io/kustomize/internal/k8sdeps"
24-
"sigs.k8s.io/kustomize/internal/k8sdeps/patch"
24+
"sigs.k8s.io/kustomize/internal/k8sdeps/transformer"
2525
"sigs.k8s.io/kustomize/pkg/commands"
2626
)
2727

@@ -30,9 +30,8 @@ func main() {
3030

3131
if err := commands.NewDefaultCommand(
3232
k8sdeps.NewKunstructuredFactoryImpl(),
33-
patch.NewPatchTransformerFactory(),
34-
k8sdeps.NewKustValidator(),
35-
k8sdeps.NewKustHash()).Execute(); err != nil {
33+
transformer.NewFactoryImpl(),
34+
k8sdeps.NewKustValidator()).Execute(); err != nil {
3635
os.Exit(1)
3736
}
3837
os.Exit(0)

pkg/commands/build/build.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525
"sigs.k8s.io/kustomize/pkg/constants"
2626
"sigs.k8s.io/kustomize/pkg/fs"
2727
"sigs.k8s.io/kustomize/pkg/ifc"
28-
"sigs.k8s.io/kustomize/pkg/ifc/patch"
28+
"sigs.k8s.io/kustomize/pkg/ifc/transformer"
2929
"sigs.k8s.io/kustomize/pkg/loader"
3030
"sigs.k8s.io/kustomize/pkg/resmap"
3131
"sigs.k8s.io/kustomize/pkg/resource"
@@ -63,8 +63,7 @@ Use different transformer configurations by passing files to kustomize
6363
func NewCmdBuild(
6464
out io.Writer, fs fs.FileSystem,
6565
kf ifc.KunstructuredFactory,
66-
ptf patch.TransformerFactory,
67-
hash ifc.Hash) *cobra.Command {
66+
ptf transformer.Factory) *cobra.Command {
6867
var o buildOptions
6968
var p string
7069

@@ -78,7 +77,7 @@ func NewCmdBuild(
7877
if err != nil {
7978
return err
8079
}
81-
return o.RunBuild(out, fs, kf, ptf, hash)
80+
return o.RunBuild(out, fs, kf, ptf)
8281
},
8382
}
8483
cmd.Flags().StringVarP(
@@ -124,8 +123,7 @@ func (o *buildOptions) Validate(args []string, p string, fs fs.FileSystem) error
124123
func (o *buildOptions) RunBuild(
125124
out io.Writer, fSys fs.FileSystem,
126125
kf ifc.KunstructuredFactory,
127-
ptf patch.TransformerFactory,
128-
hash ifc.Hash) error {
126+
ptf transformer.Factory) error {
129127
rootLoader, err := loader.NewLoader(o.kustomizationPath, "", fSys)
130128
if err != nil {
131129
return err
@@ -138,7 +136,7 @@ func (o *buildOptions) RunBuild(
138136
kt, err := target.NewKustTarget(
139137
rootLoader, fSys,
140138
resmap.NewFactory(resource.NewFactory(kf)),
141-
ptf, tc, hash)
139+
ptf, tc)
142140
if err != nil {
143141
return err
144142
}

0 commit comments

Comments
 (0)