Merge pull request #77 from uthark/golint

Fix go lint error and add golint checks to a pre-commit hook
This commit is contained in:
Jeff Regan
2018-06-10 10:35:56 -07:00
committed by GitHub
18 changed files with 58 additions and 24 deletions

View File

@@ -20,13 +20,13 @@ package resource
type GenerationBehavior int
const (
// Unspecified behavior typically treated as a Create.
// BehaviorUnspecified is an Unspecified behavior; typically treated as a Create.
BehaviorUnspecified GenerationBehavior = iota
// Make a new resource.
// BehaviorCreate makes a new resource.
BehaviorCreate
// Replace a resource.
// BehaviorReplace replaces a resource.
BehaviorReplace
// Attempt to merge a new resource with an existing resource.
// BehaviorMerge attempts to merge a new resource with an existing resource.
BehaviorMerge
)

View File

@@ -30,6 +30,7 @@ type ResId struct {
name string
}
// NewResId creates new resource identifier
func NewResId(g schema.GroupVersionKind, n string) ResId {
return ResId{gvk: g, name: n}
}
@@ -41,10 +42,12 @@ func (n ResId) String() string {
return strings.Join([]string{n.gvk.Group, n.gvk.Version, n.gvk.Kind, n.name}, "_") + ".yaml"
}
// Gvk returns Group/Version/Kind of the resource.
func (n ResId) Gvk() schema.GroupVersionKind {
return n.gvk
}
// Name returns resource name.
func (n ResId) Name() string {
return n.name
}

View File

@@ -66,11 +66,13 @@ func (r *Resource) Id() ResId {
return NewResId(r.GroupVersionKind(), r.GetName())
}
// Merge performs merge with other resource.
func (r *Resource) Merge(other *Resource) {
r.Replace(other)
mergeConfigmap(r.Object, other.Object, r.Object)
}
// Replace performs replace with other resource.
func (r *Resource) Replace(other *Resource) {
r.SetLabels(mergeStringMaps(other.GetLabels(), r.GetLabels()))
r.SetAnnotations(mergeStringMaps(other.GetAnnotations(), r.GetAnnotations()))
@@ -101,6 +103,7 @@ func mergeStringMaps(maps ...map[string]string) map[string]string {
return result
}
// GetFieldValue returns value at the given fieldpath.
func (r *Resource) GetFieldValue(fieldPath string) (string, error) {
return getFieldValue(r.UnstructuredContent(), strings.Split(fieldPath, "."))
}