mirror of https://github.com/k3s-io/k3s
Replace some occurances of kubernetes internal api types in kubectl
parent
aed9ad4b08
commit
456df2c74e
|
@ -40,7 +40,6 @@ go_test(
|
||||||
"//pkg/api/legacyscheme:go_default_library",
|
"//pkg/api/legacyscheme:go_default_library",
|
||||||
"//pkg/api/testapi:go_default_library",
|
"//pkg/api/testapi:go_default_library",
|
||||||
"//pkg/api/testing:go_default_library",
|
"//pkg/api/testing:go_default_library",
|
||||||
"//pkg/apis/apps:go_default_library",
|
|
||||||
"//pkg/apis/batch:go_default_library",
|
"//pkg/apis/batch:go_default_library",
|
||||||
"//pkg/apis/extensions:go_default_library",
|
"//pkg/apis/extensions:go_default_library",
|
||||||
"//pkg/client/clientset_generated/internalclientset:go_default_library",
|
"//pkg/client/clientset_generated/internalclientset:go_default_library",
|
||||||
|
@ -72,6 +71,7 @@ go_test(
|
||||||
"//vendor/k8s.io/apimachinery/pkg/util/sets:go_default_library",
|
"//vendor/k8s.io/apimachinery/pkg/util/sets:go_default_library",
|
||||||
"//vendor/k8s.io/apimachinery/pkg/util/uuid:go_default_library",
|
"//vendor/k8s.io/apimachinery/pkg/util/uuid:go_default_library",
|
||||||
"//vendor/k8s.io/apimachinery/pkg/watch:go_default_library",
|
"//vendor/k8s.io/apimachinery/pkg/watch:go_default_library",
|
||||||
|
"//vendor/k8s.io/client-go/kubernetes/fake:go_default_library",
|
||||||
"//vendor/k8s.io/client-go/rest:go_default_library",
|
"//vendor/k8s.io/client-go/rest:go_default_library",
|
||||||
"//vendor/k8s.io/client-go/rest/fake:go_default_library",
|
"//vendor/k8s.io/client-go/rest/fake:go_default_library",
|
||||||
"//vendor/k8s.io/client-go/testing:go_default_library",
|
"//vendor/k8s.io/client-go/testing:go_default_library",
|
||||||
|
|
|
@ -330,8 +330,7 @@ func (f *ring1Factory) Rollbacker(mapping *meta.RESTMapping) (kubectl.Rollbacker
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *ring1Factory) StatusViewer(mapping *meta.RESTMapping) (kubectl.StatusViewer, error) {
|
func (f *ring1Factory) StatusViewer(mapping *meta.RESTMapping) (kubectl.StatusViewer, error) {
|
||||||
mappingVersion := mapping.GroupVersionKind.GroupVersion()
|
clientset, err := f.clientAccessFactory.KubernetesClientSet()
|
||||||
clientset, err := f.clientAccessFactory.ClientSetForVersion(&mappingVersion)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,6 @@ import (
|
||||||
"k8s.io/kubernetes/pkg/api"
|
"k8s.io/kubernetes/pkg/api"
|
||||||
apiv1 "k8s.io/kubernetes/pkg/api/v1"
|
apiv1 "k8s.io/kubernetes/pkg/api/v1"
|
||||||
"k8s.io/kubernetes/pkg/apis/apps"
|
"k8s.io/kubernetes/pkg/apis/apps"
|
||||||
"k8s.io/kubernetes/pkg/apis/extensions"
|
|
||||||
deploymentutil "k8s.io/kubernetes/pkg/controller/deployment/util"
|
deploymentutil "k8s.io/kubernetes/pkg/controller/deployment/util"
|
||||||
sliceutil "k8s.io/kubernetes/pkg/kubectl/util/slice"
|
sliceutil "k8s.io/kubernetes/pkg/kubectl/util/slice"
|
||||||
printersinternal "k8s.io/kubernetes/pkg/printers/internalversion"
|
printersinternal "k8s.io/kubernetes/pkg/printers/internalversion"
|
||||||
|
@ -55,11 +54,11 @@ type HistoryViewer interface {
|
||||||
|
|
||||||
func HistoryViewerFor(kind schema.GroupKind, c kubernetes.Interface) (HistoryViewer, error) {
|
func HistoryViewerFor(kind schema.GroupKind, c kubernetes.Interface) (HistoryViewer, error) {
|
||||||
switch kind {
|
switch kind {
|
||||||
case extensions.Kind("Deployment"), apps.Kind("Deployment"):
|
case extensionsv1beta1.SchemeGroupVersion.WithKind("Deployment").GroupKind(), apps.Kind("Deployment"):
|
||||||
return &DeploymentHistoryViewer{c}, nil
|
return &DeploymentHistoryViewer{c}, nil
|
||||||
case apps.Kind("StatefulSet"):
|
case apps.Kind("StatefulSet"):
|
||||||
return &StatefulSetHistoryViewer{c}, nil
|
return &StatefulSetHistoryViewer{c}, nil
|
||||||
case extensions.Kind("DaemonSet"), apps.Kind("DaemonSet"):
|
case extensionsv1beta1.SchemeGroupVersion.WithKind("DaemonSet").GroupKind(), apps.Kind("DaemonSet"):
|
||||||
return &DaemonSetHistoryViewer{c}, nil
|
return &DaemonSetHistoryViewer{c}, nil
|
||||||
}
|
}
|
||||||
return nil, fmt.Errorf("no history viewer has been implemented for %q", kind)
|
return nil, fmt.Errorf("no history viewer has been implemented for %q", kind)
|
||||||
|
|
|
@ -19,13 +19,13 @@ package kubectl
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
extensionsv1beta1 "k8s.io/api/extensions/v1beta1"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
"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/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"
|
"k8s.io/kubernetes/pkg/controller/deployment/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -35,31 +35,31 @@ type StatusViewer interface {
|
||||||
}
|
}
|
||||||
|
|
||||||
// StatusViewerFor returns a StatusViewer for the resource specified by kind.
|
// 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 {
|
switch kind {
|
||||||
case extensions.Kind("Deployment"), apps.Kind("Deployment"):
|
case extensionsv1beta1.SchemeGroupVersion.WithKind("Deployment").GroupKind(), apps.Kind("Deployment"):
|
||||||
return &DeploymentStatusViewer{c.Extensions()}, nil
|
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
|
return &DaemonSetStatusViewer{c.Extensions()}, nil
|
||||||
case apps.Kind("StatefulSet"):
|
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)
|
return nil, fmt.Errorf("no status viewer has been implemented for %v", kind)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeploymentStatusViewer implements the StatusViewer interface.
|
// DeploymentStatusViewer implements the StatusViewer interface.
|
||||||
type DeploymentStatusViewer struct {
|
type DeploymentStatusViewer struct {
|
||||||
c extensionsclient.DeploymentsGetter
|
c clientextensionsv1beta1.DeploymentsGetter
|
||||||
}
|
}
|
||||||
|
|
||||||
// DaemonSetStatusViewer implements the StatusViewer interface.
|
// DaemonSetStatusViewer implements the StatusViewer interface.
|
||||||
type DaemonSetStatusViewer struct {
|
type DaemonSetStatusViewer struct {
|
||||||
c extensionsclient.DaemonSetsGetter
|
c clientextensionsv1beta1.DaemonSetsGetter
|
||||||
}
|
}
|
||||||
|
|
||||||
// StatefulSetStatusViewer implements the StatusViewer interface.
|
// StatefulSetStatusViewer implements the StatusViewer interface.
|
||||||
type StatefulSetStatusViewer struct {
|
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.
|
// 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 {
|
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 {
|
if cond != nil && cond.Reason == util.TimedOutReason {
|
||||||
return "", false, fmt.Errorf("deployment %q exceeded its progress deadline", name)
|
return "", false, fmt.Errorf("deployment %q exceeded its progress deadline", name)
|
||||||
}
|
}
|
||||||
if deployment.Status.UpdatedReplicas < deployment.Spec.Replicas {
|
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
|
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 {
|
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
|
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 {
|
if err != nil {
|
||||||
return "", false, err
|
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")
|
return "", true, fmt.Errorf("Status is available only for RollingUpdate strategy type")
|
||||||
}
|
}
|
||||||
if daemon.Generation <= daemon.Status.ObservedGeneration {
|
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 {
|
if sts.Status.ObservedGeneration == nil || sts.Generation > *sts.Status.ObservedGeneration {
|
||||||
return "Waiting for statefulset spec update to be observed...\n", false, nil
|
return "Waiting for statefulset spec update to be observed...\n", false, nil
|
||||||
}
|
}
|
||||||
if sts.Status.ReadyReplicas < sts.Spec.Replicas {
|
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
|
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.Spec.UpdateStrategy.Type == apps.RollingUpdateStatefulSetStrategyType && sts.Spec.UpdateStrategy.RollingUpdate != nil {
|
||||||
if sts.Status.UpdatedReplicas < (sts.Spec.Replicas - sts.Spec.UpdateStrategy.RollingUpdate.Partition) {
|
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",
|
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
|
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",
|
return fmt.Sprintf("partitioned roll out complete: %d new pods have been updated...\n",
|
||||||
sts.Status.UpdatedReplicas), true, nil
|
sts.Status.UpdatedReplicas), true, nil
|
||||||
|
|
|
@ -20,11 +20,11 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
apps "k8s.io/api/apps/v1beta1"
|
||||||
|
api "k8s.io/api/core/v1"
|
||||||
|
extensions "k8s.io/api/extensions/v1beta1"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/kubernetes/pkg/api"
|
"k8s.io/client-go/kubernetes/fake"
|
||||||
"k8s.io/kubernetes/pkg/apis/apps"
|
|
||||||
"k8s.io/kubernetes/pkg/apis/extensions"
|
|
||||||
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/fake"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestDeploymentStatusViewerStatus(t *testing.T) {
|
func TestDeploymentStatusViewerStatus(t *testing.T) {
|
||||||
|
@ -116,7 +116,7 @@ func TestDeploymentStatusViewerStatus(t *testing.T) {
|
||||||
Generation: test.generation,
|
Generation: test.generation,
|
||||||
},
|
},
|
||||||
Spec: extensions.DeploymentSpec{
|
Spec: extensions.DeploymentSpec{
|
||||||
Replicas: test.specReplicas,
|
Replicas: &test.specReplicas,
|
||||||
},
|
},
|
||||||
Status: test.status,
|
Status: test.status,
|
||||||
}
|
}
|
||||||
|
@ -306,7 +306,8 @@ func TestStatefulSetStatusViewerStatus(t *testing.T) {
|
||||||
generation: 1,
|
generation: 1,
|
||||||
strategy: apps.StatefulSetUpdateStrategy{Type: apps.RollingUpdateStatefulSetStrategyType,
|
strategy: apps.StatefulSetUpdateStrategy{Type: apps.RollingUpdateStatefulSetStrategyType,
|
||||||
RollingUpdate: func() *apps.RollingUpdateStatefulSetStrategy {
|
RollingUpdate: func() *apps.RollingUpdateStatefulSetStrategy {
|
||||||
return &apps.RollingUpdateStatefulSetStrategy{Partition: 2}
|
partition := int32(2)
|
||||||
|
return &apps.RollingUpdateStatefulSetStrategy{Partition: &partition}
|
||||||
}()},
|
}()},
|
||||||
status: apps.StatefulSetStatus{
|
status: apps.StatefulSetStatus{
|
||||||
ObservedGeneration: func() *int64 {
|
ObservedGeneration: func() *int64 {
|
||||||
|
@ -328,7 +329,8 @@ func TestStatefulSetStatusViewerStatus(t *testing.T) {
|
||||||
generation: 1,
|
generation: 1,
|
||||||
strategy: apps.StatefulSetUpdateStrategy{Type: apps.RollingUpdateStatefulSetStrategyType,
|
strategy: apps.StatefulSetUpdateStrategy{Type: apps.RollingUpdateStatefulSetStrategyType,
|
||||||
RollingUpdate: func() *apps.RollingUpdateStatefulSetStrategy {
|
RollingUpdate: func() *apps.RollingUpdateStatefulSetStrategy {
|
||||||
return &apps.RollingUpdateStatefulSetStrategy{Partition: 2}
|
partition := int32(2)
|
||||||
|
return &apps.RollingUpdateStatefulSetStrategy{Partition: &partition}
|
||||||
}()},
|
}()},
|
||||||
status: apps.StatefulSetStatus{
|
status: apps.StatefulSetStatus{
|
||||||
ObservedGeneration: func() *int64 {
|
ObservedGeneration: func() *int64 {
|
||||||
|
@ -373,7 +375,7 @@ func TestStatefulSetStatusViewerStatus(t *testing.T) {
|
||||||
s.Status = test.status
|
s.Status = test.status
|
||||||
s.Spec.UpdateStrategy = test.strategy
|
s.Spec.UpdateStrategy = test.strategy
|
||||||
s.Generation = test.generation
|
s.Generation = test.generation
|
||||||
client := fake.NewSimpleClientset(s).Apps()
|
client := fake.NewSimpleClientset(s).AppsV1beta1()
|
||||||
dsv := &StatefulSetStatusViewer{c: client}
|
dsv := &StatefulSetStatusViewer{c: client}
|
||||||
msg, done, err := dsv.Status(s.Namespace, s.Name, 0)
|
msg, done, err := dsv.Status(s.Namespace, s.Name, 0)
|
||||||
if test.err && err == nil {
|
if test.err && err == nil {
|
||||||
|
@ -439,7 +441,7 @@ func newStatefulSet(replicas int32) *apps.StatefulSet {
|
||||||
DNSPolicy: api.DNSClusterFirst,
|
DNSPolicy: api.DNSClusterFirst,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Replicas: replicas,
|
Replicas: &replicas,
|
||||||
UpdateStrategy: apps.StatefulSetUpdateStrategy{Type: apps.RollingUpdateStatefulSetStrategyType},
|
UpdateStrategy: apps.StatefulSetUpdateStrategy{Type: apps.RollingUpdateStatefulSetStrategyType},
|
||||||
},
|
},
|
||||||
Status: apps.StatefulSetStatus{},
|
Status: apps.StatefulSetStatus{},
|
||||||
|
|
Loading…
Reference in New Issue