Skip to content

Commit e625f87

Browse files
author
lijianguo
committed
pkg/k8s upgrade k8s api
1 parent b701e50 commit e625f87

4 files changed

Lines changed: 50 additions & 50 deletions

File tree

pkg/k8s/namespace.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package k8s
22

33
import (
4-
"k8s.io/kubernetes/pkg/api"
4+
//"k8s.io/kubernetes/pkg/api"
5+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
6+
v1 "k8s.io/api/core/v1"
57
)
68

79
// NamespaceLister is a (k8s.io/kubernetes/pkg/client/unversioned).NamespaceInterface compatible
@@ -14,5 +16,5 @@ import (
1416
// var nsl NamespaceLister
1517
// nsl = kubeClient.Namespaces()
1618
type NamespaceLister interface {
17-
List(opts api.ListOptions) (*api.NamespaceList, error)
19+
List(opts metav1.ListOptions) (*v1.NamespaceList, error)
1820
}

pkg/k8s/pull_policy.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@ package k8s
22

33
import (
44
"fmt"
5-
6-
"k8s.io/kubernetes/pkg/api"
5+
//"k8s.io/kubernetes/pkg/api"
6+
"k8s.io/api/core/v1"
77
)
88

99
var (
10-
emptyPullPolicy = api.PullPolicy("")
10+
emptyPullPolicy = v1.PullPolicy("")
1111
// ValidPullPolicies is the set of pull policies that this package considers valid
12-
ValidPullPolicies = map[api.PullPolicy]struct{}{
13-
api.PullAlways: {},
14-
api.PullIfNotPresent: {},
15-
api.PullNever: {},
12+
ValidPullPolicies = map[v1.PullPolicy]struct{}{
13+
v1.PullAlways: {},
14+
v1.PullIfNotPresent: {},
15+
v1.PullNever: {},
1616
}
1717
)
1818

@@ -27,8 +27,8 @@ func (e ErrInvalidPullPolicy) Error() string {
2727
}
2828

2929
// PullPolicyFromString converts a string into an api.PullPolicy. returns an error if the string does not match a pull policy in ValidPullPolicies()
30-
func PullPolicyFromString(ppStr string) (api.PullPolicy, error) {
31-
candidatePP := api.PullPolicy(ppStr)
30+
func PullPolicyFromString(ppStr string) (v1.PullPolicy, error) {
31+
candidatePP := v1.PullPolicy(ppStr)
3232
if _, ok := ValidPullPolicies[candidatePP]; !ok {
3333
return emptyPullPolicy, ErrInvalidPullPolicy{str: ppStr}
3434
}

pkg/k8s/secrets.go

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
package k8s
22

33
import (
4-
"k8s.io/kubernetes/pkg/api"
5-
client "k8s.io/kubernetes/pkg/client/unversioned"
6-
"k8s.io/kubernetes/pkg/watch"
4+
"k8s.io/api/core/v1"
5+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
6+
"k8s.io/apimachinery/pkg/watch"
7+
corev1 "k8s.io/client-go/kubernetes/typed/core/v1"
78
)
89

910
// FakeSecret is a mock function that can be swapped in for
1011
// (k8s.io/kubernetes/pkg/client/unversioned).SecretsInterface,
1112
// so you can unit test your code.
1213
type FakeSecret struct {
13-
FnGet func(string) (*api.Secret, error)
14-
FnCreate func(*api.Secret) (*api.Secret, error)
15-
FnUpdate func(*api.Secret) (*api.Secret, error)
14+
FnGet func(string) (*v1.Secret, error)
15+
FnCreate func(*v1.Secret) (*v1.Secret, error)
16+
FnUpdate func(*v1.Secret) (*v1.Secret, error)
1617
}
1718

1819
// Get is the interface definition.
19-
func (f *FakeSecret) Get(name string) (*api.Secret, error) {
20+
func (f *FakeSecret) Get(name string) (*v1.Secret, error) {
2021
return f.FnGet(name)
2122
}
2223

@@ -26,32 +27,32 @@ func (f *FakeSecret) Delete(name string) error {
2627
}
2728

2829
// Create is the interface definition.
29-
func (f *FakeSecret) Create(secret *api.Secret) (*api.Secret, error) {
30+
func (f *FakeSecret) Create(secret *v1.Secret) (*v1.Secret, error) {
3031
return f.FnCreate(secret)
3132
}
3233

3334
// Update is the interface definition.
34-
func (f *FakeSecret) Update(secret *api.Secret) (*api.Secret, error) {
35+
func (f *FakeSecret) Update(secret *v1.Secret) (*v1.Secret, error) {
3536
return f.FnUpdate(secret)
3637
}
3738

3839
// List is the interface definition.
39-
func (f *FakeSecret) List(opts api.ListOptions) (*api.SecretList, error) {
40-
return &api.SecretList{}, nil
40+
func (f *FakeSecret) List(opts metav1.ListOptions) (*v1.SecretList, error) {
41+
return &v1.SecretList{}, nil
4142
}
4243

4344
// Watch is the interface definition.
44-
func (f *FakeSecret) Watch(opts api.ListOptions) (watch.Interface, error) {
45+
func (f *FakeSecret) Watch(opts metav1.ListOptions) (watch.Interface, error) {
4546
return nil, nil
4647
}
4748

4849
// FakeSecretsNamespacer is a mock function that can be swapped in for an
4950
// (k8s.io/kubernetes/pkg/client/unversioned).SecretsNamespacer, so you can unit test you code
5051
type FakeSecretsNamespacer struct {
51-
Fn func(string) client.SecretsInterface
52+
Fn func(string) corev1.SecretInterface
5253
}
5354

5455
// Secrets is the interface definition.
55-
func (f *FakeSecretsNamespacer) Secrets(namespace string) client.SecretsInterface {
56+
func (f *FakeSecretsNamespacer) Secrets(namespace string) corev1.SecretInterface {
5657
return f.Fn(namespace)
5758
}

pkg/k8s/watch.go

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,56 +2,53 @@ package k8s
22

33
import (
44
"time"
5-
6-
"k8s.io/kubernetes/pkg/api"
7-
"k8s.io/kubernetes/pkg/client/cache"
8-
client "k8s.io/kubernetes/pkg/client/unversioned"
9-
"k8s.io/kubernetes/pkg/controller/framework"
10-
"k8s.io/kubernetes/pkg/labels"
11-
"k8s.io/kubernetes/pkg/runtime"
12-
"k8s.io/kubernetes/pkg/watch"
5+
"context"
6+
"k8s.io/api/core/v1"
7+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
8+
"k8s.io/client-go/tools/cache"
9+
"k8s.io/apimachinery/pkg/watch"
10+
"k8s.io/client-go/kubernetes"
11+
"k8s.io/apimachinery/pkg/runtime"
1312
)
1413

1514
var (
1615
resyncPeriod = 30 * time.Second
1716
)
17+
type StoreToPodLister struct {
18+
cache.Store
19+
}
1820

1921
//PodWatcher is a struct which holds the return values of (k8s.io/kubernetes/pkg/controller/framework).NewIndexerInformer together.
2022
type PodWatcher struct {
21-
Store cache.StoreToPodLister
22-
Controller *framework.Controller
23+
Store StoreToPodLister
24+
Controller cache.Controller
2325
}
2426

2527
//NewPodWatcher creates a new BuildPodWatcher useful to list the pods using a cache which gets updated based on the watch func.
26-
func NewPodWatcher(c *client.Client, ns string) *PodWatcher {
28+
func NewPodWatcher(c kubernetes.Interface, ns string) *PodWatcher {
2729
pw := &PodWatcher{}
2830

29-
pw.Store.Store, pw.Controller = framework.NewIndexerInformer(
31+
pw.Store.Store, pw.Controller = cache.NewIndexerInformer(
3032
&cache.ListWatch{
3133
ListFunc: podListFunc(c, ns),
3234
WatchFunc: podWatchFunc(c, ns),
3335
},
34-
&api.Pod{},
36+
&v1.Pod{},
3537
resyncPeriod,
36-
framework.ResourceEventHandlerFuncs{},
38+
cache.ResourceEventHandlerFuncs{},
3739
cache.Indexers{},
3840
)
39-
4041
return pw
4142
}
4243

43-
func podListFunc(c *client.Client, ns string) func(options api.ListOptions) (runtime.Object, error) {
44-
return func(opts api.ListOptions) (runtime.Object, error) {
45-
return c.Pods(ns).List(api.ListOptions{
46-
LabelSelector: labels.Everything(),
47-
})
44+
func podListFunc(c kubernetes.Interface, ns string) func(options metav1.ListOptions) (runtime.Object, error) {
45+
return func(opts metav1.ListOptions) (runtime.Object, error) {
46+
return c.CoreV1().Pods(ns).List(context.TODO(), metav1.ListOptions{})
4847
}
4948
}
5049

51-
func podWatchFunc(c *client.Client, ns string) func(options api.ListOptions) (watch.Interface, error) {
52-
return func(opts api.ListOptions) (watch.Interface, error) {
53-
return c.Pods(ns).Watch(api.ListOptions{
54-
LabelSelector: labels.Everything(),
55-
})
50+
func podWatchFunc(c kubernetes.Interface, ns string) func(options metav1.ListOptions) (watch.Interface, error) {
51+
return func(opts metav1.ListOptions) (watch.Interface, error) {
52+
return c.CoreV1().Pods(ns).Watch(context.TODO(), metav1.ListOptions{})
5653
}
5754
}

0 commit comments

Comments
 (0)