Use consistent names for k8s API imports
parent
6e693d22ee
commit
25579f5a58
|
@ -22,7 +22,7 @@ import (
|
|||
|
||||
"github.com/olekukonko/tablewriter"
|
||||
"github.com/spf13/cobra"
|
||||
v1 "k8s.io/api/core/v1"
|
||||
core "k8s.io/api/core/v1"
|
||||
"k8s.io/minikube/pkg/minikube/console"
|
||||
"k8s.io/minikube/pkg/minikube/exit"
|
||||
"k8s.io/minikube/pkg/minikube/machine"
|
||||
|
@ -69,6 +69,6 @@ var serviceListCmd = &cobra.Command{
|
|||
}
|
||||
|
||||
func init() {
|
||||
serviceListCmd.Flags().StringVarP(&serviceListNamespace, "namespace", "n", v1.NamespaceAll, "The services namespace")
|
||||
serviceListCmd.Flags().StringVarP(&serviceListNamespace, "namespace", "n", core.NamespaceAll, "The services namespace")
|
||||
serviceCmd.AddCommand(serviceListCmd)
|
||||
}
|
||||
|
|
|
@ -25,11 +25,10 @@ import (
|
|||
|
||||
"github.com/golang/glog"
|
||||
"github.com/pkg/errors"
|
||||
clientv1 "k8s.io/api/core/v1"
|
||||
rbacv1beta1 "k8s.io/api/rbac/v1beta1"
|
||||
apierrs "k8s.io/apimachinery/pkg/api/errors"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
core "k8s.io/api/core/v1"
|
||||
rbac "k8s.io/api/rbac/v1beta1"
|
||||
apierr "k8s.io/apimachinery/pkg/api/errors"
|
||||
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/labels"
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
"k8s.io/apimachinery/pkg/util/strategicpatch"
|
||||
|
@ -52,7 +51,7 @@ func unmarkMaster() error {
|
|||
if err != nil {
|
||||
return errors.Wrap(err, "getting core client")
|
||||
}
|
||||
n, err := client.Nodes().Get(master, v1.GetOptions{})
|
||||
n, err := client.Nodes().Get(master, meta.GetOptions{})
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "getting node %s", master)
|
||||
}
|
||||
|
@ -62,7 +61,7 @@ func unmarkMaster() error {
|
|||
return errors.Wrap(err, "json marshalling data before patch")
|
||||
}
|
||||
|
||||
newTaints := []clientv1.Taint{}
|
||||
newTaints := []core.Taint{}
|
||||
for _, taint := range n.Spec.Taints {
|
||||
if taint.Key == masterTaint {
|
||||
continue
|
||||
|
@ -77,13 +76,13 @@ func unmarkMaster() error {
|
|||
return errors.Wrapf(err, "json marshalling data after patch")
|
||||
}
|
||||
|
||||
patchBytes, err := strategicpatch.CreateTwoWayMergePatch(oldData, newData, clientv1.Node{})
|
||||
patchBytes, err := strategicpatch.CreateTwoWayMergePatch(oldData, newData, core.Node{})
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "creating strategic patch")
|
||||
}
|
||||
|
||||
if _, err := client.Nodes().Patch(n.Name, types.StrategicMergePatchType, patchBytes); err != nil {
|
||||
if apierrs.IsConflict(err) {
|
||||
if apierr.IsConflict(err) {
|
||||
return errors.Wrap(err, "strategic patch conflict")
|
||||
}
|
||||
return errors.Wrap(err, "applying strategic patch")
|
||||
|
@ -100,24 +99,24 @@ func elevateKubeSystemPrivileges() error {
|
|||
if err != nil {
|
||||
return errors.Wrap(err, "getting clientset")
|
||||
}
|
||||
clusterRoleBinding := &rbacv1beta1.ClusterRoleBinding{
|
||||
ObjectMeta: v1.ObjectMeta{
|
||||
clusterRoleBinding := &rbac.ClusterRoleBinding{
|
||||
ObjectMeta: meta.ObjectMeta{
|
||||
Name: rbacName,
|
||||
},
|
||||
Subjects: []rbacv1beta1.Subject{
|
||||
Subjects: []rbac.Subject{
|
||||
{
|
||||
Kind: "ServiceAccount",
|
||||
Name: "default",
|
||||
Namespace: "kube-system",
|
||||
},
|
||||
},
|
||||
RoleRef: rbacv1beta1.RoleRef{
|
||||
RoleRef: rbac.RoleRef{
|
||||
Kind: "ClusterRole",
|
||||
Name: "cluster-admin",
|
||||
},
|
||||
}
|
||||
|
||||
if _, err := client.RbacV1beta1().ClusterRoleBindings().Get(rbacName, metav1.GetOptions{}); err == nil {
|
||||
if _, err := client.RbacV1beta1().ClusterRoleBindings().Get(rbacName, meta.GetOptions{}); err == nil {
|
||||
glog.Infof("Role binding %s already exists. Skipping creation.", rbacName)
|
||||
return nil
|
||||
}
|
||||
|
@ -167,7 +166,7 @@ func updateKubeProxyConfigMap(k8s config.KubernetesConfig) error {
|
|||
return errors.Wrap(err, "kube-proxy not running")
|
||||
}
|
||||
|
||||
cfgMap, err := client.CoreV1().ConfigMaps("kube-system").Get("kube-proxy", metav1.GetOptions{})
|
||||
cfgMap, err := client.CoreV1().ConfigMaps("kube-system").Get("kube-proxy", meta.GetOptions{})
|
||||
if err != nil {
|
||||
return &util.RetriableError{Err: errors.Wrap(err, "getting kube-proxy configmap")}
|
||||
}
|
||||
|
@ -206,7 +205,7 @@ func updateKubeProxyConfigMap(k8s config.KubernetesConfig) error {
|
|||
return &util.RetriableError{Err: errors.Wrap(err, "updating configmap")}
|
||||
}
|
||||
|
||||
pods, err := client.CoreV1().Pods("kube-system").List(metav1.ListOptions{
|
||||
pods, err := client.CoreV1().Pods("kube-system").List(meta.ListOptions{
|
||||
LabelSelector: "k8s-app=kube-proxy",
|
||||
})
|
||||
if err != nil {
|
||||
|
@ -214,7 +213,7 @@ func updateKubeProxyConfigMap(k8s config.KubernetesConfig) error {
|
|||
}
|
||||
for _, pod := range pods.Items {
|
||||
// Retriable, as known to fail with: pods "<name>" not found
|
||||
if err := client.CoreV1().Pods(pod.Namespace).Delete(pod.Name, &metav1.DeleteOptions{}); err != nil {
|
||||
if err := client.CoreV1().Pods(pod.Namespace).Delete(pod.Name, &meta.DeleteOptions{}); err != nil {
|
||||
return &util.RetriableError{Err: errors.Wrapf(err, "deleting pod %+v", pod)}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,11 +29,11 @@ import (
|
|||
"github.com/pkg/browser"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/spf13/viper"
|
||||
v1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
core "k8s.io/api/core/v1"
|
||||
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/labels"
|
||||
"k8s.io/client-go/kubernetes"
|
||||
corev1 "k8s.io/client-go/kubernetes/typed/core/v1"
|
||||
typed_core "k8s.io/client-go/kubernetes/typed/core/v1"
|
||||
"k8s.io/client-go/tools/clientcmd"
|
||||
clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
|
||||
"k8s.io/minikube/pkg/minikube/cluster"
|
||||
|
@ -45,7 +45,7 @@ import (
|
|||
|
||||
// K8sClient represents a kubernetes client
|
||||
type K8sClient interface {
|
||||
GetCoreClient() (corev1.CoreV1Interface, error)
|
||||
GetCoreClient() (typed_core.CoreV1Interface, error)
|
||||
GetClientset(timeout time.Duration) (*kubernetes.Clientset, error)
|
||||
}
|
||||
|
||||
|
@ -60,7 +60,7 @@ func init() {
|
|||
}
|
||||
|
||||
// GetCoreClient returns a core client
|
||||
func (k *K8sClientGetter) GetCoreClient() (corev1.CoreV1Interface, error) {
|
||||
func (k *K8sClientGetter) GetCoreClient() (typed_core.CoreV1Interface, error) {
|
||||
client, err := k.GetClientset(constants.DefaultK8sClientTimeout)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "getting clientset")
|
||||
|
@ -122,7 +122,7 @@ func GetServiceURLs(api libmachine.API, namespace string, t *template.Template)
|
|||
|
||||
serviceInterface := client.Services(namespace)
|
||||
|
||||
svcs, err := serviceInterface.List(metav1.ListOptions{})
|
||||
svcs, err := serviceInterface.List(meta.ListOptions{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -160,19 +160,19 @@ func GetServiceURLsForService(api libmachine.API, namespace, service string, t *
|
|||
return printURLsForService(client, ip, service, namespace, t)
|
||||
}
|
||||
|
||||
func printURLsForService(c corev1.CoreV1Interface, ip, service, namespace string, t *template.Template) ([]string, error) {
|
||||
func printURLsForService(c typed_core.CoreV1Interface, ip, service, namespace string, t *template.Template) ([]string, error) {
|
||||
if t == nil {
|
||||
return nil, errors.New("Error, attempted to generate service url with nil --format template")
|
||||
}
|
||||
|
||||
s := c.Services(namespace)
|
||||
svc, err := s.Get(service, metav1.GetOptions{})
|
||||
svc, err := s.Get(service, meta.GetOptions{})
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "service '%s' could not be found running", service)
|
||||
}
|
||||
|
||||
e := c.Endpoints(namespace)
|
||||
endpoints, err := e.Get(service, metav1.GetOptions{})
|
||||
endpoints, err := e.Get(service, meta.GetOptions{})
|
||||
m := make(map[int32]string)
|
||||
if err == nil && endpoints != nil && len(endpoints.Subsets) > 0 {
|
||||
for _, ept := range endpoints.Subsets {
|
||||
|
@ -211,7 +211,7 @@ func CheckService(namespace string, service string) error {
|
|||
return errors.Wrap(err, "Error getting kubernetes client")
|
||||
}
|
||||
|
||||
svc, err := client.Services(namespace).Get(service, metav1.GetOptions{})
|
||||
svc, err := client.Services(namespace).Get(service, meta.GetOptions{})
|
||||
if err != nil {
|
||||
return &util.RetriableError{
|
||||
Err: errors.Wrapf(err, "Error getting service %s", service),
|
||||
|
@ -267,19 +267,19 @@ func WaitAndMaybeOpenService(api libmachine.API, namespace string, service strin
|
|||
}
|
||||
|
||||
// GetServiceListByLabel returns a ServiceList by label
|
||||
func GetServiceListByLabel(namespace string, key string, value string) (*v1.ServiceList, error) {
|
||||
func GetServiceListByLabel(namespace string, key string, value string) (*core.ServiceList, error) {
|
||||
client, err := K8s.GetCoreClient()
|
||||
if err != nil {
|
||||
return &v1.ServiceList{}, &util.RetriableError{Err: err}
|
||||
return &core.ServiceList{}, &util.RetriableError{Err: err}
|
||||
}
|
||||
return getServiceListFromServicesByLabel(client.Services(namespace), key, value)
|
||||
}
|
||||
|
||||
func getServiceListFromServicesByLabel(services corev1.ServiceInterface, key string, value string) (*v1.ServiceList, error) {
|
||||
func getServiceListFromServicesByLabel(services typed_core.ServiceInterface, key string, value string) (*core.ServiceList, error) {
|
||||
selector := labels.SelectorFromSet(labels.Set(map[string]string{key: value}))
|
||||
serviceList, err := services.List(metav1.ListOptions{LabelSelector: selector.String()})
|
||||
serviceList, err := services.List(meta.ListOptions{LabelSelector: selector.String()})
|
||||
if err != nil {
|
||||
return &v1.ServiceList{}, &util.RetriableError{Err: err}
|
||||
return &core.ServiceList{}, &util.RetriableError{Err: err}
|
||||
}
|
||||
|
||||
return serviceList, nil
|
||||
|
@ -292,7 +292,7 @@ func CreateSecret(namespace, name string, dataValues map[string]string, labels m
|
|||
return &util.RetriableError{Err: err}
|
||||
}
|
||||
secrets := client.Secrets(namespace)
|
||||
secret, _ := secrets.Get(name, metav1.GetOptions{})
|
||||
secret, _ := secrets.Get(name, meta.GetOptions{})
|
||||
|
||||
// Delete existing secret
|
||||
if len(secret.Name) > 0 {
|
||||
|
@ -309,13 +309,13 @@ func CreateSecret(namespace, name string, dataValues map[string]string, labels m
|
|||
}
|
||||
|
||||
// Create Secret
|
||||
secretObj := &v1.Secret{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
secretObj := &core.Secret{
|
||||
ObjectMeta: meta.ObjectMeta{
|
||||
Name: name,
|
||||
Labels: labels,
|
||||
},
|
||||
Data: data,
|
||||
Type: v1.SecretTypeOpaque,
|
||||
Type: core.SecretTypeOpaque,
|
||||
}
|
||||
|
||||
_, err = secrets.Create(secretObj)
|
||||
|
@ -334,7 +334,7 @@ func DeleteSecret(namespace, name string) error {
|
|||
}
|
||||
|
||||
secrets := client.Secrets(namespace)
|
||||
err = secrets.Delete(name, &metav1.DeleteOptions{})
|
||||
err = secrets.Delete(name, &meta.DeleteOptions{})
|
||||
if err != nil {
|
||||
return &util.RetriableError{Err: err}
|
||||
}
|
||||
|
|
|
@ -27,22 +27,22 @@ import (
|
|||
"github.com/docker/machine/libmachine"
|
||||
"github.com/docker/machine/libmachine/host"
|
||||
"github.com/pkg/errors"
|
||||
v1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
core "k8s.io/api/core/v1"
|
||||
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/util/intstr"
|
||||
"k8s.io/client-go/kubernetes"
|
||||
corev1 "k8s.io/client-go/kubernetes/typed/core/v1"
|
||||
typed_core "k8s.io/client-go/kubernetes/typed/core/v1"
|
||||
"k8s.io/client-go/kubernetes/typed/core/v1/fake"
|
||||
"k8s.io/minikube/pkg/minikube/config"
|
||||
"k8s.io/minikube/pkg/minikube/tests"
|
||||
)
|
||||
|
||||
type MockClientGetter struct {
|
||||
servicesMap map[string]corev1.ServiceInterface
|
||||
endpointsMap map[string]corev1.EndpointsInterface
|
||||
servicesMap map[string]typed_core.ServiceInterface
|
||||
endpointsMap map[string]typed_core.EndpointsInterface
|
||||
}
|
||||
|
||||
func (m *MockClientGetter) GetCoreClient() (corev1.CoreV1Interface, error) {
|
||||
func (m *MockClientGetter) GetCoreClient() (typed_core.CoreV1Interface, error) {
|
||||
return &MockCoreClient{
|
||||
servicesMap: m.servicesMap,
|
||||
endpointsMap: m.endpointsMap,
|
||||
|
@ -55,24 +55,24 @@ func (m *MockClientGetter) GetClientset(timeout time.Duration) (*kubernetes.Clie
|
|||
|
||||
type MockCoreClient struct {
|
||||
fake.FakeCoreV1
|
||||
servicesMap map[string]corev1.ServiceInterface
|
||||
endpointsMap map[string]corev1.EndpointsInterface
|
||||
servicesMap map[string]typed_core.ServiceInterface
|
||||
endpointsMap map[string]typed_core.EndpointsInterface
|
||||
}
|
||||
|
||||
var serviceNamespaces = map[string]corev1.ServiceInterface{
|
||||
var serviceNamespaces = map[string]typed_core.ServiceInterface{
|
||||
"default": defaultNamespaceServiceInterface,
|
||||
}
|
||||
|
||||
var defaultNamespaceServiceInterface = &MockServiceInterface{
|
||||
ServiceList: &v1.ServiceList{
|
||||
Items: []v1.Service{
|
||||
ServiceList: &core.ServiceList{
|
||||
Items: []core.Service{
|
||||
{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
ObjectMeta: meta.ObjectMeta{
|
||||
Name: "mock-dashboard",
|
||||
Namespace: "default",
|
||||
},
|
||||
Spec: v1.ServiceSpec{
|
||||
Ports: []v1.ServicePort{
|
||||
Spec: core.ServiceSpec{
|
||||
Ports: []core.ServicePort{
|
||||
{
|
||||
NodePort: int32(1111),
|
||||
TargetPort: intstr.IntOrString{
|
||||
|
@ -89,44 +89,44 @@ var defaultNamespaceServiceInterface = &MockServiceInterface{
|
|||
},
|
||||
},
|
||||
{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
ObjectMeta: meta.ObjectMeta{
|
||||
Name: "mock-dashboard-no-ports",
|
||||
Namespace: "default",
|
||||
},
|
||||
Spec: v1.ServiceSpec{
|
||||
Ports: []v1.ServicePort{},
|
||||
Spec: core.ServiceSpec{
|
||||
Ports: []core.ServicePort{},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
var endpointNamespaces = map[string]corev1.EndpointsInterface{
|
||||
var endpointNamespaces = map[string]typed_core.EndpointsInterface{
|
||||
"default": defaultNamespaceEndpointInterface,
|
||||
}
|
||||
|
||||
var defaultNamespaceEndpointInterface = &MockEndpointsInterface{}
|
||||
|
||||
func (m *MockCoreClient) Endpoints(namespace string) corev1.EndpointsInterface {
|
||||
func (m *MockCoreClient) Endpoints(namespace string) typed_core.EndpointsInterface {
|
||||
return m.endpointsMap[namespace]
|
||||
}
|
||||
|
||||
func (m *MockCoreClient) Services(namespace string) corev1.ServiceInterface {
|
||||
func (m *MockCoreClient) Services(namespace string) typed_core.ServiceInterface {
|
||||
return m.servicesMap[namespace]
|
||||
}
|
||||
|
||||
type MockEndpointsInterface struct {
|
||||
fake.FakeEndpoints
|
||||
Endpoints *v1.Endpoints
|
||||
Endpoints *core.Endpoints
|
||||
}
|
||||
|
||||
var endpointMap = map[string]*v1.Endpoints{
|
||||
var endpointMap = map[string]*core.Endpoints{
|
||||
"no-subsets": {},
|
||||
"not-ready": {
|
||||
Subsets: []v1.EndpointSubset{
|
||||
Subsets: []core.EndpointSubset{
|
||||
{
|
||||
Addresses: []v1.EndpointAddress{},
|
||||
NotReadyAddresses: []v1.EndpointAddress{
|
||||
Addresses: []core.EndpointAddress{},
|
||||
NotReadyAddresses: []core.EndpointAddress{
|
||||
{IP: "1.1.1.1"},
|
||||
{IP: "2.2.2.2"},
|
||||
},
|
||||
|
@ -134,21 +134,21 @@ var endpointMap = map[string]*v1.Endpoints{
|
|||
},
|
||||
},
|
||||
"one-ready": {
|
||||
Subsets: []v1.EndpointSubset{
|
||||
Subsets: []core.EndpointSubset{
|
||||
{
|
||||
Addresses: []v1.EndpointAddress{
|
||||
Addresses: []core.EndpointAddress{
|
||||
{IP: "1.1.1.1"},
|
||||
},
|
||||
NotReadyAddresses: []v1.EndpointAddress{
|
||||
NotReadyAddresses: []core.EndpointAddress{
|
||||
{IP: "2.2.2.2"},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"mock-dashboard": {
|
||||
Subsets: []v1.EndpointSubset{
|
||||
Subsets: []core.EndpointSubset{
|
||||
{
|
||||
Ports: []v1.EndpointPort{
|
||||
Ports: []core.EndpointPort{
|
||||
{
|
||||
Name: "port1",
|
||||
Port: int32(11111),
|
||||
|
@ -163,7 +163,7 @@ var endpointMap = map[string]*v1.Endpoints{
|
|||
},
|
||||
}
|
||||
|
||||
func (e MockEndpointsInterface) Get(name string, _ metav1.GetOptions) (*v1.Endpoints, error) {
|
||||
func (e MockEndpointsInterface) Get(name string, _ meta.GetOptions) (*core.Endpoints, error) {
|
||||
endpoint, ok := endpointMap[name]
|
||||
if !ok {
|
||||
return nil, errors.New("Endpoint not found")
|
||||
|
@ -173,12 +173,12 @@ func (e MockEndpointsInterface) Get(name string, _ metav1.GetOptions) (*v1.Endpo
|
|||
|
||||
type MockServiceInterface struct {
|
||||
fake.FakeServices
|
||||
ServiceList *v1.ServiceList
|
||||
ServiceList *core.ServiceList
|
||||
}
|
||||
|
||||
func (s MockServiceInterface) List(opts metav1.ListOptions) (*v1.ServiceList, error) {
|
||||
serviceList := &v1.ServiceList{
|
||||
Items: []v1.Service{},
|
||||
func (s MockServiceInterface) List(opts meta.ListOptions) (*core.ServiceList, error) {
|
||||
serviceList := &core.ServiceList{
|
||||
Items: []core.Service{},
|
||||
}
|
||||
if opts.LabelSelector != "" {
|
||||
keyValArr := strings.Split(opts.LabelSelector, "=")
|
||||
|
@ -195,7 +195,7 @@ func (s MockServiceInterface) List(opts metav1.ListOptions) (*v1.ServiceList, er
|
|||
return s.ServiceList, nil
|
||||
}
|
||||
|
||||
func (s MockServiceInterface) Get(name string, _ metav1.GetOptions) (*v1.Service, error) {
|
||||
func (s MockServiceInterface) Get(name string, _ meta.GetOptions) (*core.Service, error) {
|
||||
for _, svc := range s.ServiceList.Items {
|
||||
if svc.ObjectMeta.Name == name {
|
||||
return &svc, nil
|
||||
|
@ -206,10 +206,10 @@ func (s MockServiceInterface) Get(name string, _ metav1.GetOptions) (*v1.Service
|
|||
}
|
||||
|
||||
func TestGetServiceListFromServicesByLabel(t *testing.T) {
|
||||
serviceList := &v1.ServiceList{
|
||||
Items: []v1.Service{
|
||||
serviceList := &core.ServiceList{
|
||||
Items: []core.Service{
|
||||
{
|
||||
Spec: v1.ServiceSpec{
|
||||
Spec: core.ServiceSpec{
|
||||
Selector: map[string]string{
|
||||
"foo": "bar",
|
||||
},
|
||||
|
|
|
@ -24,13 +24,13 @@ import (
|
|||
"github.com/golang/glog"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/r2d4/external-storage/lib/controller"
|
||||
v1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
core "k8s.io/api/core/v1"
|
||||
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
"k8s.io/apimachinery/pkg/util/uuid"
|
||||
"k8s.io/apimachinery/pkg/util/wait"
|
||||
"k8s.io/client-go/kubernetes"
|
||||
restclient "k8s.io/client-go/rest"
|
||||
"k8s.io/client-go/rest"
|
||||
)
|
||||
|
||||
const provisionerName = "k8s.io/minikube-hostpath"
|
||||
|
@ -55,7 +55,7 @@ func NewHostPathProvisioner() controller.Provisioner {
|
|||
var _ controller.Provisioner = &hostPathProvisioner{}
|
||||
|
||||
// Provision creates a storage asset and returns a PV object representing it.
|
||||
func (p *hostPathProvisioner) Provision(options controller.VolumeOptions) (*v1.PersistentVolume, error) {
|
||||
func (p *hostPathProvisioner) Provision(options controller.VolumeOptions) (*core.PersistentVolume, error) {
|
||||
glog.Infof("Provisioning volume %v", options)
|
||||
path := path.Join(p.pvDir, options.PVName)
|
||||
if err := os.MkdirAll(path, 0777); err != nil {
|
||||
|
@ -67,21 +67,21 @@ func (p *hostPathProvisioner) Provision(options controller.VolumeOptions) (*v1.P
|
|||
return nil, err
|
||||
}
|
||||
|
||||
pv := &v1.PersistentVolume{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
pv := &core.PersistentVolume{
|
||||
ObjectMeta: meta.ObjectMeta{
|
||||
Name: options.PVName,
|
||||
Annotations: map[string]string{
|
||||
"hostPathProvisionerIdentity": string(p.identity),
|
||||
},
|
||||
},
|
||||
Spec: v1.PersistentVolumeSpec{
|
||||
Spec: core.PersistentVolumeSpec{
|
||||
PersistentVolumeReclaimPolicy: options.PersistentVolumeReclaimPolicy,
|
||||
AccessModes: options.PVC.Spec.AccessModes,
|
||||
Capacity: v1.ResourceList{
|
||||
v1.ResourceStorage: options.PVC.Spec.Resources.Requests[v1.ResourceStorage],
|
||||
Capacity: core.ResourceList{
|
||||
core.ResourceStorage: options.PVC.Spec.Resources.Requests[core.ResourceStorage],
|
||||
},
|
||||
PersistentVolumeSource: v1.PersistentVolumeSource{
|
||||
HostPath: &v1.HostPathVolumeSource{
|
||||
PersistentVolumeSource: core.PersistentVolumeSource{
|
||||
HostPath: &core.HostPathVolumeSource{
|
||||
Path: path,
|
||||
},
|
||||
},
|
||||
|
@ -93,7 +93,7 @@ func (p *hostPathProvisioner) Provision(options controller.VolumeOptions) (*v1.P
|
|||
|
||||
// Delete removes the storage asset that was created by Provision represented
|
||||
// by the given PV.
|
||||
func (p *hostPathProvisioner) Delete(volume *v1.PersistentVolume) error {
|
||||
func (p *hostPathProvisioner) Delete(volume *core.PersistentVolume) error {
|
||||
glog.Infof("Deleting volume %v", volume)
|
||||
ann, ok := volume.Annotations["hostPathProvisionerIdentity"]
|
||||
if !ok {
|
||||
|
@ -114,7 +114,7 @@ func (p *hostPathProvisioner) Delete(volume *v1.PersistentVolume) error {
|
|||
// StartStorageProvisioner will start storage provisioner server
|
||||
func StartStorageProvisioner() error {
|
||||
glog.Infof("Initializing the Minikube storage provisioner...")
|
||||
config, err := restclient.InClusterConfig()
|
||||
config, err := rest.InClusterConfig()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -22,10 +22,10 @@ import (
|
|||
|
||||
"github.com/golang/glog"
|
||||
"github.com/pkg/errors"
|
||||
appsv1 "k8s.io/api/apps/v1"
|
||||
v1 "k8s.io/api/core/v1"
|
||||
apierrs "k8s.io/apimachinery/pkg/api/errors"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
apps "k8s.io/api/apps/v1"
|
||||
core "k8s.io/api/core/v1"
|
||||
apierr "k8s.io/apimachinery/pkg/api/errors"
|
||||
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/fields"
|
||||
"k8s.io/apimachinery/pkg/labels"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
|
@ -53,11 +53,11 @@ type PodStore struct {
|
|||
}
|
||||
|
||||
// List lists the pods
|
||||
func (s *PodStore) List() []*v1.Pod {
|
||||
func (s *PodStore) List() []*core.Pod {
|
||||
objects := s.Store.List()
|
||||
pods := make([]*v1.Pod, 0)
|
||||
pods := make([]*core.Pod, 0)
|
||||
for _, o := range objects {
|
||||
pods = append(pods, o.(*v1.Pod))
|
||||
pods = append(pods, o.(*core.Pod))
|
||||
}
|
||||
return pods
|
||||
}
|
||||
|
@ -86,13 +86,13 @@ func GetClient() (kubernetes.Interface, error) {
|
|||
// NewPodStore creates a new PodStore
|
||||
func NewPodStore(c kubernetes.Interface, namespace string, label fmt.Stringer, field fmt.Stringer) *PodStore {
|
||||
lw := &cache.ListWatch{
|
||||
ListFunc: func(options metav1.ListOptions) (runtime.Object, error) {
|
||||
ListFunc: func(options meta.ListOptions) (runtime.Object, error) {
|
||||
options.LabelSelector = label.String()
|
||||
options.FieldSelector = field.String()
|
||||
obj, err := c.CoreV1().Pods(namespace).List(options)
|
||||
return runtime.Object(obj), err
|
||||
},
|
||||
WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) {
|
||||
WatchFunc: func(options meta.ListOptions) (watch.Interface, error) {
|
||||
options.LabelSelector = label.String()
|
||||
options.FieldSelector = field.String()
|
||||
return c.CoreV1().Pods(namespace).Watch(options)
|
||||
|
@ -100,13 +100,13 @@ func NewPodStore(c kubernetes.Interface, namespace string, label fmt.Stringer, f
|
|||
}
|
||||
store := cache.NewStore(cache.MetaNamespaceKeyFunc)
|
||||
stopCh := make(chan struct{})
|
||||
reflector := cache.NewReflector(lw, &v1.Pod{}, store, 0)
|
||||
reflector := cache.NewReflector(lw, &core.Pod{}, store, 0)
|
||||
go reflector.Run(stopCh)
|
||||
return &PodStore{Store: store, stopCh: stopCh, Reflector: reflector}
|
||||
}
|
||||
|
||||
// StartPods starts all pods
|
||||
func StartPods(c kubernetes.Interface, namespace string, pod v1.Pod, waitForRunning bool) error {
|
||||
func StartPods(c kubernetes.Interface, namespace string, pod core.Pod, waitForRunning bool) error {
|
||||
pod.ObjectMeta.Labels["name"] = pod.Name
|
||||
if waitForRunning {
|
||||
label := labels.SelectorFromSet(labels.Set(map[string]string{"name": pod.Name}))
|
||||
|
@ -123,7 +123,7 @@ func WaitForPodsWithLabelRunning(c kubernetes.Interface, ns string, label labels
|
|||
glog.Infof("Waiting for pod with label %q in ns %q ...", ns, label)
|
||||
lastKnownPodNumber := -1
|
||||
return wait.PollImmediate(constants.APICallRetryInterval, ReasonableStartTime, func() (bool, error) {
|
||||
listOpts := metav1.ListOptions{LabelSelector: label.String()}
|
||||
listOpts := meta.ListOptions{LabelSelector: label.String()}
|
||||
pods, err := c.CoreV1().Pods(ns).List(listOpts)
|
||||
if err != nil {
|
||||
glog.Infof("error getting Pods with label selector %q [%v]\n", label.String(), err)
|
||||
|
@ -140,7 +140,7 @@ func WaitForPodsWithLabelRunning(c kubernetes.Interface, ns string, label labels
|
|||
}
|
||||
|
||||
for _, pod := range pods.Items {
|
||||
if pod.Status.Phase != v1.PodRunning {
|
||||
if pod.Status.Phase != core.PodRunning {
|
||||
return false, nil
|
||||
}
|
||||
}
|
||||
|
@ -152,7 +152,7 @@ func WaitForPodsWithLabelRunning(c kubernetes.Interface, ns string, label labels
|
|||
// WaitForPodDelete waits for a pod to be deleted
|
||||
func WaitForPodDelete(c kubernetes.Interface, ns string, label fmt.Stringer) error {
|
||||
return wait.PollImmediate(constants.APICallRetryInterval, ReasonableMutateTime, func() (bool, error) {
|
||||
listOpts := metav1.ListOptions{LabelSelector: label.String()}
|
||||
listOpts := meta.ListOptions{LabelSelector: label.String()}
|
||||
pods, err := c.CoreV1().Pods(ns).List(listOpts)
|
||||
if err != nil {
|
||||
glog.Infof("error getting Pods with label selector %q [%v]\n", label.String(), err)
|
||||
|
@ -165,7 +165,7 @@ func WaitForPodDelete(c kubernetes.Interface, ns string, label fmt.Stringer) err
|
|||
// WaitForEvent waits for the given event to appear
|
||||
func WaitForEvent(c kubernetes.Interface, ns string, reason string) error {
|
||||
return wait.PollImmediate(constants.APICallRetryInterval, ReasonableMutateTime, func() (bool, error) {
|
||||
events, err := c.EventsV1beta1().Events("default").List(metav1.ListOptions{})
|
||||
events, err := c.EventsV1beta1().Events("default").List(meta.ListOptions{})
|
||||
if err != nil {
|
||||
glog.Infof("error getting events: %v", err)
|
||||
return false, nil
|
||||
|
@ -181,7 +181,7 @@ func WaitForEvent(c kubernetes.Interface, ns string, reason string) error {
|
|||
|
||||
// WaitForRCToStabilize waits till the RC has a matching generation/replica count between spec and status.
|
||||
func WaitForRCToStabilize(c kubernetes.Interface, ns, name string, timeout time.Duration) error {
|
||||
options := metav1.ListOptions{FieldSelector: fields.Set{
|
||||
options := meta.ListOptions{FieldSelector: fields.Set{
|
||||
"metadata.name": name,
|
||||
"metadata.namespace": ns,
|
||||
}.AsSelector().String()}
|
||||
|
@ -191,10 +191,10 @@ func WaitForRCToStabilize(c kubernetes.Interface, ns, name string, timeout time.
|
|||
}
|
||||
_, err = watch.Until(timeout, w, func(event watch.Event) (bool, error) {
|
||||
if event.Type == watch.Deleted {
|
||||
return false, apierrs.NewNotFound(schema.GroupResource{Resource: "replicationcontrollers"}, "")
|
||||
return false, apierr.NewNotFound(schema.GroupResource{Resource: "replicationcontrollers"}, "")
|
||||
}
|
||||
|
||||
rc, ok := event.Object.(*v1.ReplicationController)
|
||||
rc, ok := event.Object.(*core.ReplicationController)
|
||||
if ok {
|
||||
if rc.Name == name && rc.Namespace == ns &&
|
||||
rc.Generation <= rc.Status.ObservedGeneration &&
|
||||
|
@ -211,7 +211,7 @@ func WaitForRCToStabilize(c kubernetes.Interface, ns, name string, timeout time.
|
|||
|
||||
// WaitForDeploymentToStabilize waits till the Deployment has a matching generation/replica count between spec and status.
|
||||
func WaitForDeploymentToStabilize(c kubernetes.Interface, ns, name string, timeout time.Duration) error {
|
||||
options := metav1.ListOptions{FieldSelector: fields.Set{
|
||||
options := meta.ListOptions{FieldSelector: fields.Set{
|
||||
"metadata.name": name,
|
||||
"metadata.namespace": ns,
|
||||
}.AsSelector().String()}
|
||||
|
@ -221,9 +221,9 @@ func WaitForDeploymentToStabilize(c kubernetes.Interface, ns, name string, timeo
|
|||
}
|
||||
_, err = watch.Until(timeout, w, func(event watch.Event) (bool, error) {
|
||||
if event.Type == watch.Deleted {
|
||||
return false, apierrs.NewNotFound(schema.GroupResource{Resource: "deployments"}, "")
|
||||
return false, apierr.NewNotFound(schema.GroupResource{Resource: "deployments"}, "")
|
||||
}
|
||||
dp, ok := event.Object.(*appsv1.Deployment)
|
||||
dp, ok := event.Object.(*apps.Deployment)
|
||||
if ok {
|
||||
if dp.Name == name && dp.Namespace == ns &&
|
||||
dp.Generation <= dp.Status.ObservedGeneration &&
|
||||
|
@ -241,12 +241,12 @@ func WaitForDeploymentToStabilize(c kubernetes.Interface, ns, name string, timeo
|
|||
// WaitForService waits until the service appears (exist == true), or disappears (exist == false)
|
||||
func WaitForService(c kubernetes.Interface, namespace, name string, exist bool, interval, timeout time.Duration) error {
|
||||
err := wait.PollImmediate(interval, timeout, func() (bool, error) {
|
||||
_, err := c.CoreV1().Services(namespace).Get(name, metav1.GetOptions{})
|
||||
_, err := c.CoreV1().Services(namespace).Get(name, meta.GetOptions{})
|
||||
switch {
|
||||
case err == nil:
|
||||
glog.Infof("Service %s in namespace %s found.", name, namespace)
|
||||
return exist, nil
|
||||
case apierrs.IsNotFound(err):
|
||||
case apierr.IsNotFound(err):
|
||||
glog.Infof("Service %s in namespace %s disappeared.", name, namespace)
|
||||
return !exist, nil
|
||||
case !IsRetryableAPIError(err):
|
||||
|
@ -268,7 +268,7 @@ func WaitForService(c kubernetes.Interface, namespace, name string, exist bool,
|
|||
func WaitForServiceEndpointsNum(c kubernetes.Interface, namespace, serviceName string, expectNum int, interval, timeout time.Duration) error {
|
||||
return wait.Poll(interval, timeout, func() (bool, error) {
|
||||
glog.Infof("Waiting for amount of service:%s endpoints to be %d", serviceName, expectNum)
|
||||
list, err := c.CoreV1().Endpoints(namespace).List(metav1.ListOptions{})
|
||||
list, err := c.CoreV1().Endpoints(namespace).List(meta.ListOptions{})
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
@ -282,7 +282,7 @@ func WaitForServiceEndpointsNum(c kubernetes.Interface, namespace, serviceName s
|
|||
})
|
||||
}
|
||||
|
||||
func countEndpointsNum(e *v1.Endpoints) int {
|
||||
func countEndpointsNum(e *core.Endpoints) int {
|
||||
num := 0
|
||||
for _, sub := range e.Subsets {
|
||||
num += len(sub.Addresses)
|
||||
|
@ -292,5 +292,5 @@ func countEndpointsNum(e *v1.Endpoints) int {
|
|||
|
||||
// IsRetryableAPIError returns if this error is retryable or not
|
||||
func IsRetryableAPIError(err error) bool {
|
||||
return apierrs.IsTimeout(err) || apierrs.IsServerTimeout(err) || apierrs.IsTooManyRequests(err) || apierrs.IsInternalError(err)
|
||||
return apierr.IsTimeout(err) || apierr.IsServerTimeout(err) || apierr.IsTooManyRequests(err) || apierr.IsInternalError(err)
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ import (
|
|||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
api "k8s.io/api/core/v1"
|
||||
core "k8s.io/api/core/v1"
|
||||
storage "k8s.io/api/storage/v1"
|
||||
"k8s.io/apimachinery/pkg/labels"
|
||||
commonutil "k8s.io/minikube/pkg/util"
|
||||
|
@ -94,7 +94,7 @@ func testProvisioning(t *testing.T) {
|
|||
|
||||
// And check that it gets bound to a PV.
|
||||
checkStorage := func() error {
|
||||
pvc := api.PersistentVolumeClaim{}
|
||||
pvc := core.PersistentVolumeClaim{}
|
||||
if err := kubectlRunner.RunCommandParseOutput(pvcCmd, &pvc); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue