Skip to content

Commit

Permalink
updated kubernetes client library to version 0.21.4
Browse files Browse the repository at this point in the history
  • Loading branch information
marko-gacesa committed Sep 9, 2021
1 parent 600aaf1 commit 8d00ee5
Show file tree
Hide file tree
Showing 5 changed files with 351 additions and 112 deletions.
18 changes: 9 additions & 9 deletions engine/engine_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (k *Kubernetes) Setup(ctx context.Context, specv runtime.Spec) (err error)

if spec.Namespace != "" {
namespace := toNamespace(spec.Namespace, spec.PodSpec.Labels)
_, err = k.client.CoreV1().Namespaces().Create(namespace)
_, err = k.client.CoreV1().Namespaces().Create(ctx, namespace, metav1.CreateOptions{})
if err != nil {
log.WithError(err).Error("failed to create namespace")
return err
Expand All @@ -58,7 +58,7 @@ func (k *Kubernetes) Setup(ctx context.Context, specv runtime.Spec) (err error)

if spec.PullSecret != nil {
pullSecret := toDockerConfigSecret(spec)
_, err = k.client.CoreV1().Secrets(spec.PodSpec.Namespace).Create(pullSecret)
_, err = k.client.CoreV1().Secrets(spec.PodSpec.Namespace).Create(ctx, pullSecret, metav1.CreateOptions{})
if err != nil {
log.WithError(err).Error("failed to create pull secret")
return err
Expand All @@ -67,14 +67,14 @@ func (k *Kubernetes) Setup(ctx context.Context, specv runtime.Spec) (err error)
}

secret := toSecret(spec)
_, err = k.client.CoreV1().Secrets(spec.PodSpec.Namespace).Create(secret)
_, err = k.client.CoreV1().Secrets(spec.PodSpec.Namespace).Create(ctx, secret, metav1.CreateOptions{})
if err != nil {
log.WithError(err).Error("failed to create secret")
return err
}
log.Trace("created secret")

_, err = k.client.CoreV1().Pods(spec.PodSpec.Namespace).Create(toPod(spec))
_, err = k.client.CoreV1().Pods(spec.PodSpec.Namespace).Create(ctx, toPod(spec), metav1.CreateOptions{})
if err != nil {
log.WithError(err).Error("failed to create pod")
return err
Expand All @@ -97,27 +97,27 @@ func (k *Kubernetes) Destroy(ctx context.Context, specv runtime.Spec) error {
WithField("namespace", spec.PodSpec.Namespace)

if spec.PullSecret != nil {
if err := k.client.CoreV1().Secrets(spec.PodSpec.Namespace).Delete(spec.PullSecret.Name, &metav1.DeleteOptions{}); err != nil {
if err := k.client.CoreV1().Secrets(spec.PodSpec.Namespace).Delete(context.Background(), spec.PullSecret.Name, metav1.DeleteOptions{}); err != nil {
log.WithError(err).Error("failed to delete pull secret")
} else {
log.Trace("deleted pull secret")
}
}

if err := k.client.CoreV1().Secrets(spec.PodSpec.Namespace).Delete(spec.PodSpec.Name, &metav1.DeleteOptions{}); err != nil {
if err := k.client.CoreV1().Secrets(spec.PodSpec.Namespace).Delete(context.Background(), spec.PodSpec.Name, metav1.DeleteOptions{}); err != nil {
log.WithError(err).Error("failed to delete secret")
} else {
log.Trace("deleted secret")
}

if err := k.client.CoreV1().Pods(spec.PodSpec.Namespace).Delete(spec.PodSpec.Name, &metav1.DeleteOptions{}); err != nil {
if err := k.client.CoreV1().Pods(spec.PodSpec.Namespace).Delete(context.Background(), spec.PodSpec.Name, metav1.DeleteOptions{}); err != nil {
log.WithError(err).Error("failed to delete pod")
} else {
log.Trace("deleted pod")
}

if spec.Namespace != "" {
if err := k.client.CoreV1().Namespaces().Delete(spec.Namespace, &metav1.DeleteOptions{}); err != nil {
if err := k.client.CoreV1().Namespaces().Delete(context.Background(), spec.Namespace, metav1.DeleteOptions{}); err != nil {
log.WithError(err).Error("failed to delete namespace")
} else {
log.Trace("deleted namespace")
Expand Down Expand Up @@ -233,7 +233,7 @@ func (k *Kubernetes) fetchLogs(ctx context.Context, spec *Spec, step *Step, outp
SubResource("log").
VersionedParams(opts, scheme.ParameterCodec)

readCloser, err := req.Stream()
readCloser, err := req.Stream(ctx)
if err != nil {
logger.FromContext(ctx).
WithError(err).
Expand Down
8 changes: 4 additions & 4 deletions engine/launcher/launcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (l *Launcher) Start(ctx context.Context) {
return

case <-l.timer.C:
l.startContainers(l.requests)
l.startContainers(ctx, l.requests)
l.requests = nil

case req := <-l.requestCh:
Expand Down Expand Up @@ -126,7 +126,7 @@ func (l *Launcher) Launch(containerID, containerImage string, statusEnvs map[str
return chErr
}

func (l *Launcher) startContainers(requests map[string]*request) {
func (l *Launcher) startContainers(ctx context.Context, requests map[string]*request) {
var backoff = wait.Backoff{
Steps: 15,
Duration: 500 * time.Millisecond,
Expand All @@ -144,7 +144,7 @@ func (l *Launcher) startContainers(requests map[string]*request) {
l.podUpdateMx.Lock()
defer l.podUpdateMx.Unlock()

pod, err := l.kubeClient.CoreV1().Pods(l.podNamespace).Get(l.podName, metav1.GetOptions{})
pod, err := l.kubeClient.CoreV1().Pods(l.podNamespace).Get(ctx, l.podName, metav1.GetOptions{})
if err != nil {
return err
}
Expand All @@ -167,7 +167,7 @@ func (l *Launcher) startContainers(requests map[string]*request) {
}
}

_, err = l.kubeClient.CoreV1().Pods(l.podNamespace).Update(pod)
_, err = l.kubeClient.CoreV1().Pods(l.podNamespace).Update(ctx, pod, metav1.UpdateOptions{})

return err
})
Expand Down
6 changes: 3 additions & 3 deletions engine/podwatcher/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ func (w *KubernetesWatcher) Watch(ctx context.Context, containers chan<- []conta
lw := &cache.ListWatch{
ListFunc: func(options metav1.ListOptions) (k8sruntime.Object, error) {
options.LabelSelector = label
return w.KubeClient.CoreV1().Pods(w.PodNamespace).List(options)
return w.KubeClient.CoreV1().Pods(w.PodNamespace).List(ctx, options)
},
WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) {
options.LabelSelector = label
return w.KubeClient.CoreV1().Pods(w.PodNamespace).Watch(options)
return w.KubeClient.CoreV1().Pods(w.PodNamespace).Watch(ctx, options)
},
}

Expand Down Expand Up @@ -102,7 +102,7 @@ func (w *KubernetesWatcher) PeriodicCheck(ctx context.Context, containers chan<-
return nil

case <-ticker.C:
pod, err := w.KubeClient.CoreV1().Pods(w.PodNamespace).Get(w.PodName, metav1.GetOptions{})
pod, err := w.KubeClient.CoreV1().Pods(w.PodNamespace).Get(ctx, w.PodName, metav1.GetOptions{})
if err != nil {
logrus.
WithError(err).
Expand Down
14 changes: 6 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,17 @@ require (
github.com/drone/runner-go v1.8.0
github.com/drone/signal v1.0.0
github.com/ghodss/yaml v1.0.0
github.com/golang/mock v1.3.1
github.com/google/go-cmp v0.3.0
github.com/googleapis/gnostic v0.2.0 // indirect
github.com/golang/mock v1.4.1
github.com/google/go-cmp v0.5.4
github.com/gosimple/slug v1.9.0
github.com/joho/godotenv v1.3.0
github.com/kelseyhightower/envconfig v1.4.0
github.com/mattn/go-isatty v0.0.8
github.com/opencontainers/go-digest v1.0.0-rc1 // indirect
github.com/sirupsen/logrus v1.4.2
golang.org/x/sync v0.0.0-20190423024810-112230192c58
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9
gopkg.in/alecthomas/kingpin.v2 v2.2.6
gopkg.in/inf.v0 v0.9.1 // indirect
k8s.io/api v0.0.0-20190918155943-95b840bb6a1f
k8s.io/apimachinery v0.0.0-20190913080033-27d36303b655
k8s.io/client-go v0.0.0-20190918160344-1fbdaa4c8d90
k8s.io/api v0.21.4
k8s.io/apimachinery v0.21.4
k8s.io/client-go v0.21.4
)
Loading

0 comments on commit 8d00ee5

Please sign in to comment.