@@ -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 {
4850func 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