hide core/v1 behind interface

This commit is contained in:
Jingfang Liu
2018-10-09 14:51:37 -07:00
parent 0faef46773
commit f783486057
17 changed files with 112 additions and 77 deletions

View File

@@ -19,11 +19,11 @@ package resource
import (
"log"
"k8s.io/apimachinery/pkg/runtime"
"sigs.k8s.io/kustomize/internal/k8sdeps"
"sigs.k8s.io/kustomize/pkg/fs"
"sigs.k8s.io/kustomize/pkg/ifc"
internal "sigs.k8s.io/kustomize/pkg/internal/error"
"sigs.k8s.io/kustomize/pkg/patch"
"sigs.k8s.io/kustomize/pkg/types"
)
// Factory makes instances of Resource.
@@ -36,16 +36,6 @@ func NewFactory(kf ifc.KunstructuredFactory) *Factory {
return &Factory{kf: kf}
}
// WithBehavior returns a new instance of Resource.
// TODO(monopole): This runtime dependence must be refactored away.
// The logic calling this has to move to k8sdeps.
func (rf *Factory) WithBehavior(
obj runtime.Object, b ifc.GenerationBehavior) (*Resource, error) {
// TODO(monopole): This k8sdeps dependence must be refactored away.
u, err := k8sdeps.NewKunstructuredFromObject(obj)
return &Resource{Kunstructured: u, b: b}, err
}
// FromMap returns a new instance of Resource.
func (rf *Factory) FromMap(m map[string]interface{}) *Resource {
return &Resource{
@@ -93,3 +83,34 @@ func (rf *Factory) SliceFromBytes(in []byte) ([]*Resource, error) {
}
return result, nil
}
// Set sets the filesystem and loader for the underlying factory
func (rf *Factory) Set(fs fs.FileSystem, ldr ifc.Loader) {
rf.kf.Set(fs, ldr)
}
// MakeConfigMap makes an instance of Resource for ConfigMap
func (rf *Factory) MakeConfigMap(args *types.ConfigMapArgs) (*Resource, error) {
u, err := rf.kf.MakeConfigMap(args)
if err != nil {
return nil, err
}
return &Resource{Kunstructured: u, b: fixBehavior(args.Behavior)}, nil
}
// MakeSecret makes an instance of Resource for Secret
func (rf *Factory) MakeSecret(args *types.SecretArgs) (*Resource, error) {
u, err := rf.kf.MakeSecret(args)
if err != nil {
return nil, err
}
return &Resource{Kunstructured: u, b: fixBehavior(args.Behavior)}, nil
}
func fixBehavior(s string) ifc.GenerationBehavior {
b := ifc.NewGenerationBehavior(s)
if b == ifc.BehaviorUnspecified {
return ifc.BehaviorCreate
}
return b
}