Skip to content

Commit cb75823

Browse files
author
lijianguo
committed
chore(builder): upgrade k8s.io api version
1 parent 8a550fd commit cb75823

18 files changed

Lines changed: 363 additions & 198 deletions

boot.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
"github.com/drycc/builder/pkg/sys"
1919
pkglog "github.com/drycc/pkg/log"
2020
"github.com/kelseyhightower/envconfig"
21-
kcl "k8s.io/kubernetes/pkg/client/unversioned"
21+
"github.com/drycc/builder/pkg/k8s"
2222
)
2323

2424
const (
@@ -68,22 +68,22 @@ func main() {
6868
os.Exit(1)
6969
}
7070

71-
kubeClient, err := kcl.NewInCluster()
71+
kubeClient, err := k8s.NewInCluster()
7272
if err != nil {
7373
log.Printf("Error getting kubernetes client [%s]", err)
7474
os.Exit(1)
7575
}
7676
log.Printf("Starting health check server on port %d", cnf.HealthSrvPort)
7777
healthSrvCh := make(chan error)
7878
go func() {
79-
if err := healthsrv.Start(cnf, kubeClient.Namespaces(), storageDriver, circ); err != nil {
79+
if err := healthsrv.Start(cnf, kubeClient.CoreV1().Namespaces(), storageDriver, circ); err != nil {
8080
healthSrvCh <- err
8181
}
8282
}()
8383
log.Printf("Starting deleted app cleaner")
8484
cleanerErrCh := make(chan error)
8585
go func() {
86-
if err := cleaner.Run(gitHomeDir, kubeClient.Namespaces(), fs, cnf.CleanerPollSleepDuration(), storageDriver); err != nil {
86+
if err := cleaner.Run(gitHomeDir, kubeClient.CoreV1().Namespaces(), fs, cnf.CleanerPollSleepDuration(), storageDriver); err != nil {
8787
cleanerErrCh <- err
8888
}
8989
}()

go.mod

Lines changed: 7 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,48 +3,22 @@ module github.com/drycc/builder
33
go 1.13
44

55
require (
6-
github.com/Azure/azure-sdk-for-go v35.0.0+incompatible // indirect
7-
github.com/PuerkitoBio/purell v1.1.1 // indirect
8-
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
9-
github.com/Sirupsen/logrus v0.7.3 // indirect
6+
github.com/Sirupsen/logrus v0.0.0-00010101000000-000000000000 // indirect
107
github.com/arschles/assert v0.0.0-20150820224400-6882f85ccdc7
118
github.com/aws/aws-sdk-go v1.28.2
12-
github.com/blang/semver v3.5.0+incompatible // indirect
139
github.com/codegangsta/cli v1.9.0
14-
github.com/cyphar/filepath-securejoin v0.2.2 // indirect
1510
github.com/docker/distribution v0.0.0-00010101000000-000000000000
16-
github.com/docker/docker v1.4.2-0.20150722082610-0f5c9d301b9b // indirect
17-
github.com/docker/go-units v0.4.0 // indirect
1811
github.com/drycc/controller-sdk-go v0.0.0-20190417134318-39a6c81f21f3
1912
github.com/drycc/pkg v0.0.0-20190121053802-5c1dfa7b5446
20-
github.com/emicklei/go-restful v2.9.5+incompatible // indirect
21-
github.com/ghodss/yaml v1.0.0 // indirect
22-
github.com/go-ini/ini v1.8.6 // indirect
23-
github.com/google/cadvisor v0.35.0 // indirect
24-
github.com/google/gofuzz v1.1.0 // indirect
25-
github.com/gorilla/context v1.1.1 // indirect
26-
github.com/gorilla/mux v1.7.0 // indirect
27-
github.com/goware/urlx v0.0.0-20160722204212-8bb4a2e4339f // indirect
28-
github.com/juju/ratelimit v0.0.0-20151125201925-77ed1c8a0121 // indirect
13+
github.com/gorilla/mux v1.7.4 // indirect
14+
github.com/goware/urlx v0.3.1 // indirect
2915
github.com/kelseyhightower/envconfig v1.2.0
30-
github.com/mitchellh/mapstructure v1.1.2 // indirect
31-
github.com/ncw/swift v1.0.20-0.20151102203822-c54732e87b0b // indirect
32-
github.com/opencontainers/runc v0.0.7
33-
github.com/opencontainers/runtime-spec v1.0.2 // indirect
3416
github.com/pborman/uuid v1.2.0
35-
github.com/prometheus/client_golang v1.0.0 // indirect
36-
github.com/prometheus/client_model v0.2.0 // indirect
37-
github.com/spf13/pflag v1.0.5 // indirect
38-
github.com/ugorji/go v0.0.0-20160211161415-f4485b318aad // indirect
39-
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9
40-
golang.org/x/lint v0.0.0-20200302205851-738671d3881b // indirect
41-
golang.org/x/tools v0.0.0-20200725200936-102e7d357031 // indirect
42-
google.golang.org/api v0.6.1-0.20190607001116-5213b8090861 // indirect
43-
google.golang.org/cloud v0.0.0-20151119220103-975617b05ea8 // indirect
44-
google.golang.org/grpc v1.26.0 // indirect
17+
golang.org/x/crypto v0.0.0-20200220183623-bac4c82f6975
4518
gopkg.in/yaml.v2 v2.2.8
46-
k8s.io/kubernetes v1.2.4
47-
speter.net/go/exp/math/dec/inf v0.0.0-00010101000000-000000000000 // indirect
19+
k8s.io/api v0.18.6
20+
k8s.io/apimachinery v0.18.6
21+
k8s.io/client-go v0.18.6
4822
)
4923

5024
replace (

go.sum

Lines changed: 108 additions & 0 deletions
Large diffs are not rendered by default.

pkg/cleaner/cleaner.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,19 @@ import (
99
"regexp"
1010
"strings"
1111
"time"
12+
"context"
1213

13-
"github.com/docker/distribution/context"
14+
//"github.com/docker/distribution/context"
1415
storagedriver "github.com/docker/distribution/registry/storage/driver"
1516
"github.com/drycc/builder/pkg/gitreceive"
1617
"github.com/drycc/builder/pkg/k8s"
1718
"github.com/drycc/builder/pkg/sys"
1819
"github.com/drycc/pkg/log"
19-
"k8s.io/kubernetes/pkg/api"
20-
"k8s.io/kubernetes/pkg/fields"
21-
"k8s.io/kubernetes/pkg/labels"
20+
corev1 "k8s.io/api/core/v1"
21+
//"k8s.io/apimachinery/pkg/labels"
22+
//"k8s.io/apimachinery/pkg/fields"
23+
//"k8s.io/apimachinery/pkg/apis/meta/internalversion"
24+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2225
)
2326

2427
const (
@@ -46,7 +49,7 @@ func localDirs(gitHome string, filter func(string) bool) ([]string, error) {
4649
}
4750

4851
// getDiff gets the directories that are not in namespaceList
49-
func getDiff(namespaceList []api.Namespace, dirs []string) []string {
52+
func getDiff(namespaceList []corev1.Namespace, dirs []string) []string {
5053
var ret []string
5154

5255
// create a set of lowercase namespace names
@@ -123,7 +126,7 @@ func deleteFromObjectStore(app string, storageDriver storagedriver.StorageDriver
123126
// On any error, it uses log messages to output a human readable description of what happened.
124127
func Run(gitHome string, nsLister k8s.NamespaceLister, fs sys.FS, pollSleepDuration time.Duration, storageDriver storagedriver.StorageDriver) error {
125128
for {
126-
nsList, err := nsLister.List(api.ListOptions{LabelSelector: labels.Everything(), FieldSelector: fields.Everything()})
129+
nsList, err := nsLister.List(context.TODO(), metav1.ListOptions{})
127130
if err != nil {
128131
log.Err("Cleaner error listing namespaces (%s)", err)
129132
continue

pkg/cleaner/cleaner_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ import (
77
"testing"
88

99
"github.com/arschles/assert"
10-
"k8s.io/kubernetes/pkg/api"
10+
"k8s.io/api/core/v1"
11+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1112
)
1213

1314
func TestGetDiff(t *testing.T) {
14-
nsList := []api.Namespace{
15-
{ObjectMeta: api.ObjectMeta{Name: "app1"}},
16-
{ObjectMeta: api.ObjectMeta{Name: "app2"}},
15+
nsList := []v1.Namespace{
16+
{ObjectMeta: metav1.ObjectMeta{Name: "app1"}},
17+
{ObjectMeta: metav1.ObjectMeta{Name: "app2"}},
1718
}
1819
dirList := []string{"app1", "app3"}
1920
diff := getDiff(nsList, dirList)

pkg/gitreceive/build.go

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"os/exec"
1111
"path/filepath"
1212
"strings"
13+
ctx "context"
1314

1415
"github.com/docker/distribution/context"
1516
storagedriver "github.com/docker/distribution/registry/storage/driver"
@@ -22,8 +23,9 @@ import (
2223
"github.com/drycc/controller-sdk-go/hooks"
2324
"github.com/drycc/pkg/log"
2425
"gopkg.in/yaml.v2"
25-
"k8s.io/kubernetes/pkg/api"
26-
client "k8s.io/kubernetes/pkg/client/unversioned"
26+
"k8s.io/client-go/kubernetes"
27+
corev1 "k8s.io/api/core/v1"
28+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2729
)
2830

2931
// repoCmd returns exec.Command(first, others...) with its current working directory repoDir
@@ -48,7 +50,8 @@ func run(cmd *exec.Cmd) error {
4850
func build(
4951
conf *Config,
5052
storageDriver storagedriver.StorageDriver,
51-
kubeClient *client.Client,
53+
//kubeClient *client.Client,
54+
kubeClient *kubernetes.Clientset,
5255
fs sys.FS,
5356
env sys.Env,
5457
builderKey,
@@ -146,7 +149,7 @@ func build(
146149
return fmt.Errorf("uploading %s to %s (%v)", absAppTgz, slugBuilderInfo.TarKey(), err)
147150
}
148151

149-
var pod *api.Pod
152+
var pod *corev1.Pod
150153
var buildPodName string
151154
image := appName
152155

@@ -160,7 +163,7 @@ func build(
160163
registryLocation := conf.RegistryLocation
161164
registryEnv := make(map[string]string)
162165
if registryLocation != "on-cluster" {
163-
registryEnv, err = getRegistryDetails(kubeClient, &image, registryLocation, conf.PodNamespace)
166+
registryEnv, err = getRegistryDetails(kubeClient.CoreV1(), &image, registryLocation, conf.PodNamespace)
164167
if err != nil {
165168
return fmt.Errorf("error getting private registry details %s", err)
166169
}
@@ -192,12 +195,12 @@ func build(
192195
cacheKey = slugBuilderInfo.CacheKey()
193196
}
194197
envSecretName := fmt.Sprintf("%s-build-env", appName)
195-
err = createAppEnvConfigSecret(kubeClient.Secrets(conf.PodNamespace), envSecretName, appConf.Values)
198+
err = createAppEnvConfigSecret(kubeClient.CoreV1().Secrets(conf.PodNamespace), envSecretName, appConf.Values)
196199
if err != nil {
197200
return fmt.Errorf("error creating/updating secret %s: (%s)", envSecretName, err)
198201
}
199202
defer func() {
200-
if err := kubeClient.Secrets(conf.PodNamespace).Delete(envSecretName); err != nil {
203+
if err := kubeClient.CoreV1().Secrets(conf.PodNamespace).Delete(ctx.TODO(), envSecretName, metav1.DeleteOptions{}); err != nil {
201204
log.Info("unable to delete secret %s (%s)", envSecretName, err)
202205
}
203206
}()
@@ -227,14 +230,14 @@ func build(
227230
log.Debug("Error creating json representation of pod spec: %v", err)
228231
}
229232

230-
podsInterface := kubeClient.Pods(conf.PodNamespace)
233+
podsInterface := kubeClient.CoreV1().Pods(conf.PodNamespace)
231234

232-
newPod, err := podsInterface.Create(pod)
235+
newPod, err := podsInterface.Create(ctx.TODO(), pod, metav1.CreateOptions{})
233236
if err != nil {
234237
return fmt.Errorf("creating builder pod (%s)", err)
235238
}
236239

237-
pw := k8s.NewPodWatcher(kubeClient, conf.PodNamespace)
240+
pw := k8s.NewPodWatcher(*kubeClient, conf.PodNamespace)
238241
stopCh := make(chan struct{})
239242
defer close(stopCh)
240243
go pw.Controller.Run(stopCh)
@@ -243,12 +246,12 @@ func build(
243246
return fmt.Errorf("watching events for builder pod startup (%s)", err)
244247
}
245248

246-
req := kubeClient.Get().Namespace(newPod.Namespace).Name(newPod.Name).Resource("pods").SubResource("log").VersionedParams(
247-
&api.PodLogOptions{
249+
req := kubeClient.CoreV1().RESTClient().Get().Namespace(newPod.Namespace).Name(newPod.Name).Resource("pods").SubResource("log").VersionedParams(
250+
&corev1.PodLogOptions{
248251
Follow: true,
249-
}, api.ParameterCodec)
252+
}, metav1.ParameterCodec)
250253

251-
rc, err := req.Stream()
254+
rc, err := req.Stream(ctx.TODO())
252255
if err != nil {
253256
return fmt.Errorf("attempting to stream logs (%s)", err)
254257
}
@@ -274,7 +277,7 @@ func build(
274277
}
275278
log.Debug("Done")
276279
log.Debug("Checking for builder pod exit code")
277-
buildPod, err := kubeClient.Pods(newPod.Namespace).Get(newPod.Name)
280+
buildPod, err := kubeClient.CoreV1().Pods(newPod.Namespace).Get(ctx.TODO(), newPod.Name, metav1.GetOptions{})
278281
if err != nil {
279282
return fmt.Errorf("error getting builder pod status (%s)", err)
280283
}

0 commit comments

Comments
 (0)