forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
meta.go
41 lines (34 loc) · 1.45 KB
/
meta.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package meta
import (
"fmt"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/validation/field"
kapi "k8s.io/kubernetes/pkg/api"
buildapi "github.com/openshift/origin/pkg/build/api"
)
// ImageReferenceMutateFunc is passed a reference representing an image, and may alter
// the Name, Kind, and Namespace fields of the reference. If an error is returned the
// object may still be mutated under the covers.
type ImageReferenceMutateFunc func(ref *kapi.ObjectReference) error
type ImageReferenceMutator interface {
// Mutate invokes fn on every image reference in the object. If fn returns an error,
// a field.Error is added to the list to be returned. Mutate does not terminate early
// if errors are detected.
Mutate(fn ImageReferenceMutateFunc) field.ErrorList
}
var errNoImageMutator = fmt.Errorf("No list of images available for this object")
// GetImageReferenceMutator returns a mutator for the provided object, or an error if no
// such mutator is defined.
func GetImageReferenceMutator(obj runtime.Object) (ImageReferenceMutator, error) {
switch t := obj.(type) {
case *buildapi.Build:
return &buildSpecMutator{spec: &t.Spec.CommonSpec, path: field.NewPath("spec")}, nil
case *buildapi.BuildConfig:
return &buildSpecMutator{spec: &t.Spec.CommonSpec, path: field.NewPath("spec")}, nil
default:
if spec, path, err := GetPodSpec(obj); err == nil {
return &podSpecMutator{spec: spec, path: path}, nil
}
return nil, errNoImageMutator
}
}