Merge pull request #1004 from Liujingfang1/prune

change field name: prune -> inventory
This commit is contained in:
Kubernetes Prow Robot
2019-04-22 15:14:07 -07:00
committed by GitHub
10 changed files with 29 additions and 28 deletions

View File

@@ -19,8 +19,8 @@ package transformer
import ( import (
"sigs.k8s.io/kustomize/k8sdeps/transformer/hash" "sigs.k8s.io/kustomize/k8sdeps/transformer/hash"
"sigs.k8s.io/kustomize/k8sdeps/transformer/inventory"
"sigs.k8s.io/kustomize/k8sdeps/transformer/patch" "sigs.k8s.io/kustomize/k8sdeps/transformer/patch"
"sigs.k8s.io/kustomize/k8sdeps/transformer/prune"
"sigs.k8s.io/kustomize/pkg/resource" "sigs.k8s.io/kustomize/pkg/resource"
"sigs.k8s.io/kustomize/pkg/transformers" "sigs.k8s.io/kustomize/pkg/transformers"
"sigs.k8s.io/kustomize/pkg/types" "sigs.k8s.io/kustomize/pkg/types"
@@ -44,6 +44,6 @@ func (p *FactoryImpl) MakeHashTransformer() transformers.Transformer {
return hash.NewNameHashTransformer() return hash.NewNameHashTransformer()
} }
func (p *FactoryImpl) MakePruneTransformer(arg *types.Prune, namespace string, append bool) transformers.Transformer { func (p *FactoryImpl) MakeInventoryTransformer(arg *types.Inventory, namespace string, append bool) transformers.Transformer {
return prune.NewPruneTransformer(arg, namespace, append) return inventory.NewInventoryTransformer(arg, namespace, append)
} }

View File

@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
package prune package inventory
import ( import (
"fmt" "fmt"
@@ -31,33 +31,33 @@ import (
//const PruneAnnotation = "kustomize.k8s.io/PruneRevision" //const PruneAnnotation = "kustomize.k8s.io/PruneRevision"
const PruneAnnotation = "current" const PruneAnnotation = "current"
// pruneTransformer compute the ConfigMap used in prune // inventoryTransformer compute the ConfigMap used in prune
type pruneTransformer struct { type inventoryTransformer struct {
append bool append bool
cmName string cmName string
cmNamespace string cmNamespace string
} }
var _ transformers.Transformer = &pruneTransformer{} var _ transformers.Transformer = &inventoryTransformer{}
// NewPruneTransformer makes a pruneTransformer. // NewInventoryTransformer makes a inventoryTransformer.
func NewPruneTransformer(p *types.Prune, namespace string, append bool) transformers.Transformer { func NewInventoryTransformer(p *types.Inventory, namespace string, append bool) transformers.Transformer {
if p == nil || p.Type != "ConfigMap" || p.ConfigMap.Namespace != namespace { if p == nil || p.Type != "ConfigMap" || p.ConfigMap.Namespace != namespace {
return transformers.NewNoOpTransformer() return transformers.NewNoOpTransformer()
} }
return &pruneTransformer{ return &inventoryTransformer{
append: append, append: append,
cmName: p.ConfigMap.Name, cmName: p.ConfigMap.Name,
cmNamespace: p.ConfigMap.Namespace, cmNamespace: p.ConfigMap.Namespace,
} }
} }
// Transform generates a prune ConfigMap based on the input ResMap. // Transform generates an inventory ConfigMap based on the input ResMap.
// this tranformer doesn't change existing resources - // this tranformer doesn't change existing resources -
// it just visits resources and accumulates information to make a new ConfigMap. // it just visits resources and accumulates information to make a new ConfigMap.
// The prune ConfigMap is used to support the pruning command in the client side tool, // The prune ConfigMap is used to support the pruning command in the client side tool,
// which is proposed in https://github.com/kubernetes/enhancements/pull/810 // which is proposed in https://github.com/kubernetes/enhancements/pull/810
func (o *pruneTransformer) Transform(m resmap.ResMap) error { func (o *inventoryTransformer) Transform(m resmap.ResMap) error {
var keys []string var keys []string
for _, r := range m { for _, r := range m {
s := r.PruneString() s := r.PruneString()

View File

@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
package prune package inventory
import ( import (
"reflect" "reflect"
@@ -103,7 +103,7 @@ func makeResMap() resmap.ResMap {
return objs return objs
} }
func TestPruneTransformer(t *testing.T) { func TestInventoryTransformer(t *testing.T) {
rf := resource.NewFactory( rf := resource.NewFactory(
kunstruct.NewKunstructuredFactoryImpl()) kunstruct.NewKunstructuredFactoryImpl())
@@ -138,7 +138,7 @@ func TestPruneTransformer(t *testing.T) {
resid.NewResIdWithPrefixNamespace(cmap, "pruneCM", "", "default"): pruneMap, resid.NewResIdWithPrefixNamespace(cmap, "pruneCM", "", "default"): pruneMap,
} }
p := &types.Prune{ p := &types.Inventory{
Type: "ConfigMap", Type: "ConfigMap",
ConfigMap: types.NameArgs{ ConfigMap: types.NameArgs{
Name: "pruneCM", Name: "pruneCM",
@@ -148,7 +148,7 @@ func TestPruneTransformer(t *testing.T) {
objs := makeResMap() objs := makeResMap()
// include the original resmap; only return the ConfigMap for pruning // include the original resmap; only return the ConfigMap for pruning
tran := NewPruneTransformer(p, "default", false) tran := NewInventoryTransformer(p, "default", false)
tran.Transform(objs) tran.Transform(objs)
if !reflect.DeepEqual(objs, expected) { if !reflect.DeepEqual(objs, expected) {
@@ -160,7 +160,7 @@ func TestPruneTransformer(t *testing.T) {
expected = objs.DeepCopy(rf) expected = objs.DeepCopy(rf)
expected[resid.NewResIdWithPrefixNamespace(cmap, "pruneCM", "", "default")] = pruneMap expected[resid.NewResIdWithPrefixNamespace(cmap, "pruneCM", "", "default")] = pruneMap
// append the ConfigMap for pruning to the original resmap // append the ConfigMap for pruning to the original resmap
tran = NewPruneTransformer(p, "default", true) tran = NewInventoryTransformer(p, "default", true)
tran.Transform(objs) tran.Transform(objs)
if !reflect.DeepEqual(objs, expected) { if !reflect.DeepEqual(objs, expected) {

View File

@@ -178,8 +178,8 @@ func NewCmdBuildPrune(
var o Options var o Options
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "alpha-prune [path]", Use: "alpha-inventory [path]",
Short: "Print configmap to prune previous applied objects", Short: "Print the inventory object which contains a list of all other objects",
Example: examples, Example: examples,
SilenceUsage: true, SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {

View File

@@ -69,7 +69,7 @@ func determineFieldOrder() []string {
"Configurations", "Configurations",
"Generators", "Generators",
"Transformers", "Transformers",
"Prune", "Inventory",
} }
// Add deprecated fields here. // Add deprecated fields here.

View File

@@ -48,7 +48,7 @@ func TestFieldOrder(t *testing.T) {
"Configurations", "Configurations",
"Generators", "Generators",
"Transformers", "Transformers",
"Prune", "Inventory",
} }
actual := determineFieldOrder() actual := determineFieldOrder()
if len(expected) != len(actual) { if len(expected) != len(actual) {

View File

@@ -27,5 +27,5 @@ import (
type Factory interface { type Factory interface {
MakePatchTransformer(slice []*resource.Resource, rf *resource.Factory) (transformers.Transformer, error) MakePatchTransformer(slice []*resource.Resource, rf *resource.Factory) (transformers.Transformer, error)
MakeHashTransformer() transformers.Transformer MakeHashTransformer() transformers.Transformer
MakePruneTransformer(p *types.Prune, namespace string, append bool) transformers.Transformer MakeInventoryTransformer(p *types.Inventory, namespace string, append bool) transformers.Transformer
} }

View File

@@ -147,7 +147,7 @@ func (kt *KustTarget) MakeCustomizedResMap() (resmap.ResMap, error) {
} }
rm := ra.ResMap() rm := ra.ResMap()
pt := kt.tFactory.MakePruneTransformer(kt.kustomization.Prune, kt.kustomization.Namespace, true) pt := kt.tFactory.MakeInventoryTransformer(kt.kustomization.Inventory, kt.kustomization.Namespace, true)
err = pt.Transform(rm) err = pt.Transform(rm)
if err != nil { if err != nil {
return nil, err return nil, err
@@ -177,7 +177,7 @@ func (kt *KustTarget) MakePruneConfigMap() (resmap.ResMap, error) {
} }
rm := ra.ResMap() rm := ra.ResMap()
pt := kt.tFactory.MakePruneTransformer(kt.kustomization.Prune, kt.kustomization.Namespace, false) pt := kt.tFactory.MakeInventoryTransformer(kt.kustomization.Inventory, kt.kustomization.Namespace, false)
err = pt.Transform(rm) err = pt.Transform(rm)
if err != nil { if err != nil {
return nil, err return nil, err

View File

@@ -28,7 +28,7 @@ resources:
- service.yaml - service.yaml
- secret.yaml - secret.yaml
prune: inventory:
type: ConfigMap type: ConfigMap
configMap: configMap:
name: haha name: haha

View File

@@ -137,8 +137,9 @@ type Kustomization struct {
// Transformers is a list of files containing transformers // Transformers is a list of files containing transformers
Transformers []string `json:"transformers,omitempty" yaml:"transformers,omitempty"` Transformers []string `json:"transformers,omitempty" yaml:"transformers,omitempty"`
// Name of the ConfigMap used in Prune // Inventory appends an object that contains the record
Prune *Prune `json:"prune,omitempty" yaml:"prune:omitempty"` // of all other objects, which can be used in apply, prune and delete
Inventory *Inventory `json:"inventory,omitempty" yaml:"inventory:omitempty"`
} }
// DealWithMissingFields fills the missing fields // DealWithMissingFields fills the missing fields
@@ -293,7 +294,7 @@ type KVSource struct {
Args []string `json:"args,omitempty" yaml:"args,omitempty"` Args []string `json:"args,omitempty" yaml:"args,omitempty"`
} }
type Prune struct { type Inventory struct {
Type string `json:"type,omitempty" yaml:"type,omitempty"` Type string `json:"type,omitempty" yaml:"type,omitempty"`
ConfigMap NameArgs `json:"configMap,omitempty" yaml:"configMap,omitempty"` ConfigMap NameArgs `json:"configMap,omitempty" yaml:"configMap,omitempty"`
} }