remove todo: switch UpdatePodSpecForObject to work on v1.PodSpec, use info.VersionedObject, and avoid conversion completely

This commit is contained in:
zhengjiajin
2017-11-11 02:36:12 +08:00
parent 4793b714d8
commit dc312142ab
21 changed files with 1525 additions and 228 deletions

View File

@@ -19,30 +19,30 @@ package env
import (
"fmt"
"k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/kubernetes/pkg/api/resource"
api "k8s.io/kubernetes/pkg/apis/core"
clientset "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
"k8s.io/client-go/kubernetes"
"k8s.io/kubernetes/pkg/api/v1/resource"
"k8s.io/kubernetes/pkg/fieldpath"
)
// ResourceStore defines a new resource store data structure.
type ResourceStore struct {
SecretStore map[string]*api.Secret
ConfigMapStore map[string]*api.ConfigMap
SecretStore map[string]*v1.Secret
ConfigMapStore map[string]*v1.ConfigMap
}
// NewResourceStore returns a pointer to a new resource store data structure.
func NewResourceStore() *ResourceStore {
return &ResourceStore{
SecretStore: make(map[string]*api.Secret),
ConfigMapStore: make(map[string]*api.ConfigMap),
SecretStore: make(map[string]*v1.Secret),
ConfigMapStore: make(map[string]*v1.ConfigMap),
}
}
// getSecretRefValue returns the value of a secret in the supplied namespace
func getSecretRefValue(client clientset.Interface, namespace string, store *ResourceStore, secretSelector *api.SecretKeySelector) (string, error) {
func getSecretRefValue(client kubernetes.Interface, namespace string, store *ResourceStore, secretSelector *v1.SecretKeySelector) (string, error) {
secret, ok := store.SecretStore[secretSelector.Name]
if !ok {
var err error
@@ -60,7 +60,7 @@ func getSecretRefValue(client clientset.Interface, namespace string, store *Reso
}
// getConfigMapRefValue returns the value of a configmap in the supplied namespace
func getConfigMapRefValue(client clientset.Interface, namespace string, store *ResourceStore, configMapSelector *api.ConfigMapKeySelector) (string, error) {
func getConfigMapRefValue(client kubernetes.Interface, namespace string, store *ResourceStore, configMapSelector *v1.ConfigMapKeySelector) (string, error) {
configMap, ok := store.ConfigMapStore[configMapSelector.Name]
if !ok {
var err error
@@ -77,17 +77,17 @@ func getConfigMapRefValue(client clientset.Interface, namespace string, store *R
}
// getFieldRef returns the value of the supplied path in the given object
func getFieldRef(obj runtime.Object, from *api.EnvVarSource) (string, error) {
func getFieldRef(obj runtime.Object, from *v1.EnvVarSource) (string, error) {
return fieldpath.ExtractFieldPathAsString(obj, from.FieldRef.FieldPath)
}
// getResourceFieldRef returns the value of a resource in the given container
func getResourceFieldRef(from *api.EnvVarSource, c *api.Container) (string, error) {
func getResourceFieldRef(from *v1.EnvVarSource, c *v1.Container) (string, error) {
return resource.ExtractContainerResourceValue(from.ResourceFieldRef, c)
}
// GetEnvVarRefValue returns the value referenced by the supplied EnvVarSource given the other supplied information.
func GetEnvVarRefValue(kc clientset.Interface, ns string, store *ResourceStore, from *api.EnvVarSource, obj runtime.Object, c *api.Container) (string, error) {
func GetEnvVarRefValue(kc kubernetes.Interface, ns string, store *ResourceStore, from *v1.EnvVarSource, obj runtime.Object, c *v1.Container) (string, error) {
if from.SecretKeyRef != nil {
return getSecretRefValue(kc, ns, store, from.SecretKeyRef)
}
@@ -108,7 +108,7 @@ func GetEnvVarRefValue(kc clientset.Interface, ns string, store *ResourceStore,
}
// GetEnvVarRefString returns a text description of whichever field is set within the supplied EnvVarSource argument.
func GetEnvVarRefString(from *api.EnvVarSource) string {
func GetEnvVarRefString(from *v1.EnvVarSource) string {
if from.ConfigMapKeyRef != nil {
return fmt.Sprintf("configmap %s, key %s", from.ConfigMapKeyRef.Name, from.ConfigMapKeyRef.Key)
}