Replace some occurances of kubernetes internal api types in kubectl

This commit is contained in:
yland
2017-10-24 16:56:54 +01:00
parent aed9ad4b08
commit 456df2c74e
5 changed files with 37 additions and 35 deletions

View File

@@ -19,13 +19,13 @@ package kubectl
import (
"fmt"
extensionsv1beta1 "k8s.io/api/extensions/v1beta1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/kubernetes"
clientappsv1beta1 "k8s.io/client-go/kubernetes/typed/apps/v1beta1"
clientextensionsv1beta1 "k8s.io/client-go/kubernetes/typed/extensions/v1beta1"
"k8s.io/kubernetes/pkg/apis/apps"
"k8s.io/kubernetes/pkg/apis/extensions"
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
appsclient "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/typed/apps/internalversion"
extensionsclient "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/typed/extensions/internalversion"
"k8s.io/kubernetes/pkg/controller/deployment/util"
)
@@ -35,31 +35,31 @@ type StatusViewer interface {
}
// StatusViewerFor returns a StatusViewer for the resource specified by kind.
func StatusViewerFor(kind schema.GroupKind, c internalclientset.Interface) (StatusViewer, error) {
func StatusViewerFor(kind schema.GroupKind, c kubernetes.Interface) (StatusViewer, error) {
switch kind {
case extensions.Kind("Deployment"), apps.Kind("Deployment"):
case extensionsv1beta1.SchemeGroupVersion.WithKind("Deployment").GroupKind(), apps.Kind("Deployment"):
return &DeploymentStatusViewer{c.Extensions()}, nil
case extensions.Kind("DaemonSet"), apps.Kind("DaemonSet"):
case extensionsv1beta1.SchemeGroupVersion.WithKind("DaemonSet").GroupKind(), apps.Kind("DaemonSet"):
return &DaemonSetStatusViewer{c.Extensions()}, nil
case apps.Kind("StatefulSet"):
return &StatefulSetStatusViewer{c.Apps()}, nil
return &StatefulSetStatusViewer{c.AppsV1beta1()}, nil
}
return nil, fmt.Errorf("no status viewer has been implemented for %v", kind)
}
// DeploymentStatusViewer implements the StatusViewer interface.
type DeploymentStatusViewer struct {
c extensionsclient.DeploymentsGetter
c clientextensionsv1beta1.DeploymentsGetter
}
// DaemonSetStatusViewer implements the StatusViewer interface.
type DaemonSetStatusViewer struct {
c extensionsclient.DaemonSetsGetter
c clientextensionsv1beta1.DaemonSetsGetter
}
// StatefulSetStatusViewer implements the StatusViewer interface.
type StatefulSetStatusViewer struct {
c appsclient.StatefulSetsGetter
c clientappsv1beta1.StatefulSetsGetter
}
// Status returns a message describing deployment status, and a bool value indicating if the status is considered done.
@@ -78,12 +78,12 @@ func (s *DeploymentStatusViewer) Status(namespace, name string, revision int64)
}
}
if deployment.Generation <= deployment.Status.ObservedGeneration {
cond := util.GetDeploymentConditionInternal(deployment.Status, extensions.DeploymentProgressing)
cond := util.GetDeploymentCondition(deployment.Status, extensionsv1beta1.DeploymentProgressing)
if cond != nil && cond.Reason == util.TimedOutReason {
return "", false, fmt.Errorf("deployment %q exceeded its progress deadline", name)
}
if deployment.Status.UpdatedReplicas < deployment.Spec.Replicas {
return fmt.Sprintf("Waiting for rollout to finish: %d out of %d new replicas have been updated...\n", deployment.Status.UpdatedReplicas, deployment.Spec.Replicas), false, nil
if deployment.Spec.Replicas != nil && deployment.Status.UpdatedReplicas < *deployment.Spec.Replicas {
return fmt.Sprintf("Waiting for rollout to finish: %d out of %d new replicas have been updated...\n", deployment.Status.UpdatedReplicas, *deployment.Spec.Replicas), false, nil
}
if deployment.Status.Replicas > deployment.Status.UpdatedReplicas {
return fmt.Sprintf("Waiting for rollout to finish: %d old replicas are pending termination...\n", deployment.Status.Replicas-deployment.Status.UpdatedReplicas), false, nil
@@ -104,7 +104,7 @@ func (s *DaemonSetStatusViewer) Status(namespace, name string, revision int64) (
if err != nil {
return "", false, err
}
if daemon.Spec.UpdateStrategy.Type != extensions.RollingUpdateDaemonSetStrategyType {
if daemon.Spec.UpdateStrategy.Type != extensionsv1beta1.RollingUpdateDaemonSetStrategyType {
return "", true, fmt.Errorf("Status is available only for RollingUpdate strategy type")
}
if daemon.Generation <= daemon.Status.ObservedGeneration {
@@ -131,13 +131,15 @@ func (s *StatefulSetStatusViewer) Status(namespace, name string, revision int64)
if sts.Status.ObservedGeneration == nil || sts.Generation > *sts.Status.ObservedGeneration {
return "Waiting for statefulset spec update to be observed...\n", false, nil
}
if sts.Status.ReadyReplicas < sts.Spec.Replicas {
return fmt.Sprintf("Waiting for %d pods to be ready...\n", sts.Spec.Replicas-sts.Status.ReadyReplicas), false, nil
if sts.Spec.Replicas != nil && sts.Status.ReadyReplicas < *sts.Spec.Replicas {
return fmt.Sprintf("Waiting for %d pods to be ready...\n", *sts.Spec.Replicas-sts.Status.ReadyReplicas), false, nil
}
if sts.Spec.UpdateStrategy.Type == apps.RollingUpdateStatefulSetStrategyType && sts.Spec.UpdateStrategy.RollingUpdate != nil {
if sts.Status.UpdatedReplicas < (sts.Spec.Replicas - sts.Spec.UpdateStrategy.RollingUpdate.Partition) {
return fmt.Sprintf("Waiting for partitioned roll out to finish: %d out of %d new pods have been updated...\n",
sts.Status.UpdatedReplicas, (sts.Spec.Replicas - sts.Spec.UpdateStrategy.RollingUpdate.Partition)), false, nil
if sts.Spec.Replicas != nil && sts.Spec.UpdateStrategy.RollingUpdate.Partition != nil {
if sts.Status.UpdatedReplicas < (*sts.Spec.Replicas - *sts.Spec.UpdateStrategy.RollingUpdate.Partition) {
return fmt.Sprintf("Waiting for partitioned roll out to finish: %d out of %d new pods have been updated...\n",
sts.Status.UpdatedReplicas, (*sts.Spec.Replicas - *sts.Spec.UpdateStrategy.RollingUpdate.Partition)), false, nil
}
}
return fmt.Sprintf("partitioned roll out complete: %d new pods have been updated...\n",
sts.Status.UpdatedReplicas), true, nil