Skip to content

Allow objects to request resolution, not just images #14795

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions contrib/completions/bash/oc
Original file line number Diff line number Diff line change
Expand Up @@ -15912,6 +15912,8 @@ _oc_set_image-lookup()
flags_with_completion+=("-f")
flags_completion+=("__handle_filename_extension_flag yaml|yml|json")
local_nonpersistent_flags+=("--filename=")
flags+=("--list")
local_nonpersistent_flags+=("--list")
flags+=("--local")
local_nonpersistent_flags+=("--local")
flags+=("--no-headers")
Expand Down
2 changes: 2 additions & 0 deletions contrib/completions/bash/openshift
Original file line number Diff line number Diff line change
Expand Up @@ -21490,6 +21490,8 @@ _openshift_cli_set_image-lookup()
flags_with_completion+=("-f")
flags_completion+=("__handle_filename_extension_flag yaml|yml|json")
local_nonpersistent_flags+=("--filename=")
flags+=("--list")
local_nonpersistent_flags+=("--list")
flags+=("--local")
local_nonpersistent_flags+=("--local")
flags+=("--no-headers")
Expand Down
2 changes: 2 additions & 0 deletions contrib/completions/zsh/oc
Original file line number Diff line number Diff line change
Expand Up @@ -16061,6 +16061,8 @@ _oc_set_image-lookup()
flags_with_completion+=("-f")
flags_completion+=("__handle_filename_extension_flag yaml|yml|json")
local_nonpersistent_flags+=("--filename=")
flags+=("--list")
local_nonpersistent_flags+=("--list")
flags+=("--local")
local_nonpersistent_flags+=("--local")
flags+=("--no-headers")
Expand Down
2 changes: 2 additions & 0 deletions contrib/completions/zsh/openshift
Original file line number Diff line number Diff line change
Expand Up @@ -21639,6 +21639,8 @@ _openshift_cli_set_image-lookup()
flags_with_completion+=("-f")
flags_completion+=("__handle_filename_extension_flag yaml|yml|json")
local_nonpersistent_flags+=("--filename=")
flags+=("--list")
local_nonpersistent_flags+=("--list")
flags+=("--local")
local_nonpersistent_flags+=("--local")
flags+=("--no-headers")
Expand Down
54 changes: 54 additions & 0 deletions pkg/api/meta/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package meta
import (
"fmt"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/validation/field"
kapi "k8s.io/kubernetes/pkg/api"
Expand Down Expand Up @@ -42,3 +43,56 @@ func GetImageReferenceMutator(obj runtime.Object) (ImageReferenceMutator, error)
return nil, errNoImageMutator
}
}

type AnnotationAccessor interface {
// Annotations returns a map representing annotations. Not mutable.
Annotations() map[string]string
// SetAnnotations sets representing annotations onto the object.
SetAnnotations(map[string]string)
// TemplateAnnotations returns a map representing annotations on a nested template in the object. Not mutable.
// If no template is present bool will be false.
TemplateAnnotations() (map[string]string, bool)
// SetTemplateAnnotations sets annotations on a nested template in the object.
// If no template is present bool will be false.
SetTemplateAnnotations(map[string]string) bool
}

type annotationsAccessor struct {
object metav1.Object
template metav1.Object
}

func (a annotationsAccessor) Annotations() map[string]string {
return a.object.GetAnnotations()
}

func (a annotationsAccessor) TemplateAnnotations() (map[string]string, bool) {
if a.template == nil {
return nil, false
}
return a.template.GetAnnotations(), true
}

func (a annotationsAccessor) SetAnnotations(annotations map[string]string) {
a.object.SetAnnotations(annotations)
}

func (a annotationsAccessor) SetTemplateAnnotations(annotations map[string]string) bool {
if a.template == nil {
return false
}
a.template.SetAnnotations(annotations)
return true
}

// GetAnnotationAccessor returns an accessor for the provided object or false if the object
// does not support accessing annotations.
func GetAnnotationAccessor(obj runtime.Object) (AnnotationAccessor, bool) {
switch t := obj.(type) {
case metav1.Object:
templateObject, _ := GetTemplateMetaObject(obj)
return annotationsAccessor{object: t, template: templateObject}, true
default:
return nil, false
}
}
87 changes: 83 additions & 4 deletions pkg/api/meta/pods.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package meta
import (
"fmt"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/util/validation/field"
Expand Down Expand Up @@ -92,7 +93,9 @@ func GetPodSpec(obj runtime.Object) (*kapi.PodSpec, *field.Path, error) {
case *kapi.PodTemplate:
return &r.Template.Spec, field.NewPath("template", "spec"), nil
case *kapi.ReplicationController:
return &r.Spec.Template.Spec, field.NewPath("spec", "template", "spec"), nil
if r.Spec.Template != nil {
return &r.Spec.Template.Spec, field.NewPath("spec", "template", "spec"), nil
}
case *extensions.DaemonSet:
return &r.Spec.Template.Spec, field.NewPath("spec", "template", "spec"), nil
case *extensions.Deployment:
Expand All @@ -114,7 +117,9 @@ func GetPodSpec(obj runtime.Object) (*kapi.PodSpec, *field.Path, error) {
case *securityapi.PodSecurityPolicyReview:
return &r.Spec.Template.Spec, field.NewPath("spec", "template", "spec"), nil
case *deployapi.DeploymentConfig:
return &r.Spec.Template.Spec, field.NewPath("spec", "template", "spec"), nil
if r.Spec.Template != nil {
return &r.Spec.Template.Spec, field.NewPath("spec", "template", "spec"), nil
}
}
return nil, nil, errNoPodSpec
}
Expand All @@ -129,7 +134,9 @@ func GetPodSpecV1(obj runtime.Object) (*kapiv1.PodSpec, *field.Path, error) {
case *kapiv1.PodTemplate:
return &r.Template.Spec, field.NewPath("template", "spec"), nil
case *kapiv1.ReplicationController:
return &r.Spec.Template.Spec, field.NewPath("spec", "template", "spec"), nil
if r.Spec.Template != nil {
return &r.Spec.Template.Spec, field.NewPath("spec", "template", "spec"), nil
}
case *extensionsv1beta1.DaemonSet:
return &r.Spec.Template.Spec, field.NewPath("spec", "template", "spec"), nil
case *extensionsv1beta1.Deployment:
Expand All @@ -153,11 +160,83 @@ func GetPodSpecV1(obj runtime.Object) (*kapiv1.PodSpec, *field.Path, error) {
case *securityapiv1.PodSecurityPolicyReview:
return &r.Spec.Template.Spec, field.NewPath("spec", "template", "spec"), nil
case *deployapiv1.DeploymentConfig:
return &r.Spec.Template.Spec, field.NewPath("spec", "template", "spec"), nil
if r.Spec.Template != nil {
return &r.Spec.Template.Spec, field.NewPath("spec", "template", "spec"), nil
}
}
return nil, nil, errNoPodSpec
}

// GetTemplateMetaObject returns a mutable metav1.Object interface for the template
// the object contains, or false if no such object is available.
func GetTemplateMetaObject(obj runtime.Object) (metav1.Object, bool) {
switch r := obj.(type) {
case *kapiv1.PodTemplate:
return &r.Template.ObjectMeta, true
case *kapiv1.ReplicationController:
if r.Spec.Template != nil {
return &r.Spec.Template.ObjectMeta, true
}
case *extensionsv1beta1.DaemonSet:
return &r.Spec.Template.ObjectMeta, true
case *extensionsv1beta1.Deployment:
return &r.Spec.Template.ObjectMeta, true
case *extensionsv1beta1.ReplicaSet:
return &r.Spec.Template.ObjectMeta, true
case *batchv1.Job:
return &r.Spec.Template.ObjectMeta, true
case *batchv2alpha1.CronJob:
return &r.Spec.JobTemplate.Spec.Template.ObjectMeta, true
case *batchv2alpha1.JobTemplate:
return &r.Template.Spec.Template.ObjectMeta, true
case *appsv1beta1.StatefulSet:
return &r.Spec.Template.ObjectMeta, true
case *appsv1beta1.Deployment:
return &r.Spec.Template.ObjectMeta, true
case *securityapiv1.PodSecurityPolicySubjectReview:
return &r.Spec.Template.ObjectMeta, true
case *securityapiv1.PodSecurityPolicySelfSubjectReview:
return &r.Spec.Template.ObjectMeta, true
case *securityapiv1.PodSecurityPolicyReview:
return &r.Spec.Template.ObjectMeta, true
case *deployapiv1.DeploymentConfig:
if r.Spec.Template != nil {
return &r.Spec.Template.ObjectMeta, true
}
case *kapi.PodTemplate:
return &r.Template.ObjectMeta, true
case *kapi.ReplicationController:
if r.Spec.Template != nil {
return &r.Spec.Template.ObjectMeta, true
}
case *extensions.DaemonSet:
return &r.Spec.Template.ObjectMeta, true
case *extensions.Deployment:
return &r.Spec.Template.ObjectMeta, true
case *extensions.ReplicaSet:
return &r.Spec.Template.ObjectMeta, true
case *batch.Job:
return &r.Spec.Template.ObjectMeta, true
case *batch.CronJob:
return &r.Spec.JobTemplate.Spec.Template.ObjectMeta, true
case *batch.JobTemplate:
return &r.Template.Spec.Template.ObjectMeta, true
case *apps.StatefulSet:
return &r.Spec.Template.ObjectMeta, true
case *securityapi.PodSecurityPolicySubjectReview:
return &r.Spec.Template.ObjectMeta, true
case *securityapi.PodSecurityPolicySelfSubjectReview:
return &r.Spec.Template.ObjectMeta, true
case *securityapi.PodSecurityPolicyReview:
return &r.Spec.Template.ObjectMeta, true
case *deployapi.DeploymentConfig:
if r.Spec.Template != nil {
return &r.Spec.Template.ObjectMeta, true
}
}
return nil, false
}

type containerMutator struct {
*kapi.Container
}
Expand Down
Loading