Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to client-go 10.0.0 and refactor dynamic client usage #348

Merged
merged 16 commits into from
Jan 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
590 changes: 140 additions & 450 deletions Gopkg.lock

Large diffs are not rendered by default.

95 changes: 60 additions & 35 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,53 +8,78 @@ required = ["k8s.io/kubernetes/pkg/kubectl/cmd/util"]
name = "github.com/pulumi/pulumi"
branch = "master"

[[override]]
name = "github.com/ugorji/go"
revision = "8c0409fcbb70099c748d71f714529204975f6c3f"

[[override]]
name = "github.com/cbroglie/mustache"
revision = "v1.0.0"

# ---------------------------------------------------------------------------
# NOTE: the k8s.io dependencies, (including go-autorest) are highly sensitive
# to change! They are pinned at versions where (1) they compile (nb.,
# surprisingly challenging) and (2) their quirks are well-understood. cf.,
# [here][1], [here][2], and [here][3].
#
# [1]: https://medium.com/@andy.goldstein/upgrading-kubernetes-client-go-from-v4-to-v5-bbd5025fe381
# [2]: https://medium.com/@vladimirvivien/using-gos-dep-to-organize-your-kubernetes-client-go-dependencies-509ddc766ed3
# [3]: https://blog.heptio.com/straighten-out-your-kubernetes-client-go-dependencies-heptioprotip-8baeed46fe7d
# ---------------------------------------------------------------------------
# Kubernetes packages
#

[[constraint]]
name = "k8s.io/api"
revision = "kubernetes-1.10.2"
name = "k8s.io/kubernetes"
version = "1.13.1"

[[constraint]]
name = "k8s.io/client-go"
version = "10.0.0"

[[constraint]]
name = "k8s.io/apimachinery"
version = "kubernetes-1.10.2"
version = "kubernetes-1.13.0"

[[constraint]]
name = "k8s.io/api"
revision = "kubernetes-1.13.0"

[[override]]
name = "k8s.io/apiserver"
version = "kubernetes-1.10.2"
name = "sigs.k8s.io/kustomize"
hausdorff marked this conversation as resolved.
Show resolved Hide resolved
version = "1.0.11"

[[constraint]]
name = "k8s.io/client-go"
version = "7.0.0"
#
# Cloud provider packages
#

[[constraint]]
name = "k8s.io/kubernetes"
version = "v1.10.2"
[[override]]
name = "github.com/aws/aws-sdk-go"
version = "1.13.12"

# vendor/k8s.io/client-go/plugin/pkg/client/auth/azure/azure.go:247:4: cannot use json.Number(expiresIn) (type json.Number) as type string in field value
# vendor/k8s.io/client-go/plugin/pkg/client/auth/azure/azure.go:248:4: cannot use json.Number(expiresOn) (type json.Number) as type string in field value
# vendor/k8s.io/client-go/plugin/pkg/client/auth/azure/azure.go:249:4: cannot use json.Number(expiresOn) (type json.Number) as type string in field value
[[override]]
name = "github.com/russross/blackfriday"
version = "v1.5"
name = "github.com/Azure/go-autorest"
version = "v11.1.0"

# ---------------------------------------------------------------------------
# End sensitive k8s.io dependencies.
# ---------------------------------------------------------------------------
#
# Third party packages
#

[[constraint]]
name = "github.com/yudai/gojsondiff"
revision = "9209d1532c51cabe0439993586a71c207b09a0ac"
name = "github.com/cbroglie/mustache"
version = "v1.0.0"

[[override]]
name = "github.com/json-iterator/go"
version = "1.1.5"

[[override]]
name = "github.com/satori/go.uuid"
version = "1.2.0"

[[override]]
name = "github.com/spf13/cobra"
version = "0.0.3"

[[override]]
name = "github.com/spf13/pflag"
version = "1.0.2"

# vendor/github.com/census-instrumentation/opencensus-proto/gen-go/agent/trace/v1/trace_service.pb.go:296:21: c.cc.NewStream undefined (type *grpc.ClientConn has no field or method NewStream)
# vendor/github.com/census-instrumentation/opencensus-proto/gen-go/agent/trace/v1/trace_service.pb.go:327:21: c.cc.NewStream undefined (type *grpc.ClientConn has no field or method NewStream)
[[override]]
name = "google.golang.org/grpc"
version = "1.18.0"

# vendor/google.golang.org/grpc/internal/channelz/types_linux.go:41:15: undefined: unix.GetsockoptLinger
# vendor/google.golang.org/grpc/internal/channelz/types_linux.go:44:15: undefined: unix.GetsockoptTimeval
# vendor/google.golang.org/grpc/internal/channelz/types_linux.go:47:15: undefined: unix.GetsockoptTimeval
[[override]]
name = "golang.org/x/sys"
revision = "1c9583448a9c3aa0f9a6a5241bf73c0bd8aafded"
1 change: 0 additions & 1 deletion examples/provider/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Copyright 2016-2018, Pulumi Corporation. All rights reserved.

import * as pulumi from "@pulumi/pulumi";
import * as k8s from "@pulumi/kubernetes";
import * as fs from "fs";
import * as os from "os";
Expand Down
73 changes: 32 additions & 41 deletions pkg/await/apps_deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ import (

"github.com/golang/glog"
"github.com/pkg/errors"
"github.com/pulumi/pulumi-kubernetes/pkg/client"
"github.com/pulumi/pulumi-kubernetes/pkg/clients"
"github.com/pulumi/pulumi-kubernetes/pkg/openapi"
"github.com/pulumi/pulumi/pkg/diag"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/watch"
"k8s.io/client-go/dynamic"
)
Expand Down Expand Up @@ -137,15 +136,15 @@ func (dia *deploymentInitAwaiter) Await() error {
// corresponding ReplicaSet), and therefore there is no rollout to mark as "Progressing".
//

replicaSetClient, podClient, pvcClient, err := dia.makeClients()
deploymentClient, replicaSetClient, podClient, pvcClient, err := dia.makeClients()
if err != nil {
return err
}

// Create Deployment watcher.
deploymentWatcher, err := dia.config.clientForResource.Watch(metav1.ListOptions{})
deploymentWatcher, err := deploymentClient.Watch(metav1.ListOptions{})
if err != nil {
return errors.Wrapf(err, "Could not set up watch for Deployment object %q",
return errors.Wrapf(err, "could not set up watch for Deployment object %q",
dia.config.currentInputs.GetName())
}
defer deploymentWatcher.Stop()
Expand Down Expand Up @@ -185,13 +184,13 @@ func (dia *deploymentInitAwaiter) Await() error {

func (dia *deploymentInitAwaiter) Read() error {
// Get clients needed to retrieve live versions of relevant Deployments, ReplicaSets, and Pods.
replicaSetClient, podClient, pvcClient, err := dia.makeClients()
deploymentClient, replicaSetClient, podClient, pvcClient, err := dia.makeClients()
if err != nil {
return err
}

// Get live versions of Deployment, ReplicaSets, and Pods.
deployment, err := dia.config.clientForResource.Get(dia.config.currentInputs.GetName(),
deployment, err := deploymentClient.Get(dia.config.currentInputs.GetName(),
metav1.GetOptions{})
if err != nil {
// IMPORTANT: Do not wrap this error! If this is a 404, the provider need to know so that it
Expand Down Expand Up @@ -226,8 +225,7 @@ func (dia *deploymentInitAwaiter) Read() error {
pvcList = &unstructured.UnstructuredList{Items: []unstructured.Unstructured{}}
}

return dia.read(deployment, rsList.(*unstructured.UnstructuredList),
podList.(*unstructured.UnstructuredList), pvcList.(*unstructured.UnstructuredList))
return dia.read(deployment, rsList, podList, pvcList)
}

func (dia *deploymentInitAwaiter) read(
Expand Down Expand Up @@ -650,13 +648,13 @@ func (dia *deploymentInitAwaiter) aggregatePodErrors() ([]string, []string) {
}
}

scheduleErrors := []string{}
scheduleErrors := make([]string, 0)
hausdorff marked this conversation as resolved.
Show resolved Hide resolved
for message, count := range scheduleErrorCounts {
message = fmt.Sprintf("%d Pods failed to schedule because: %s", count, message)
scheduleErrors = append(scheduleErrors, message)
}

containerErrors := []string{}
containerErrors := make([]string, 0)
for message, count := range containerErrorCounts {
message = fmt.Sprintf("%d Pods failed to run because: %s", count, message)
containerErrors = append(containerErrors, message)
Expand All @@ -670,7 +668,7 @@ func (dia *deploymentInitAwaiter) getFailedPersistentValueClaims() []string {
return nil
}

failed := []string{}
failed := make([]string, 0)
for _, pvc := range dia.pvcs {
phase, _ := openapi.Pluck(pvc.Object, "status", "phase")
if phase != statusBound {
Expand All @@ -681,7 +679,7 @@ func (dia *deploymentInitAwaiter) getFailedPersistentValueClaims() []string {
}

func (dia *deploymentInitAwaiter) errorMessages() []string {
messages := []string{}
messages := make([]string, 0)
for _, message := range dia.deploymentErrors {
messages = append(messages, message)
}
Expand Down Expand Up @@ -725,43 +723,36 @@ func (dia *deploymentInitAwaiter) errorMessages() []string {
}

func (dia *deploymentInitAwaiter) makeClients() (
replicaSetClient, podClient, pvcClient dynamic.ResourceInterface, err error,
deploymentClient, replicaSetClient, podClient, pvcClient dynamic.ResourceInterface, err error,
) {
replicaSetClient, err = client.FromGVK(dia.config.pool, dia.config.disco,
schema.GroupVersionKind{
Group: "extensions",
Version: "v1beta1",
Kind: "ReplicaSet",
}, dia.config.currentInputs.GetNamespace())
deploymentClient, err = clients.ResourceClient(
clients.Deployment, dia.config.currentInputs.GetNamespace(), dia.config.clientSet)
if err != nil {
return nil, nil, nil, errors.Wrapf(err,
"Could not make client to watch ReplicaSets associated with Deployment %q",
err = errors.Wrapf(err, "Could not make client to watch Deployment %q",
dia.config.currentInputs.GetName())
return
}

podClient, err = client.FromGVK(dia.config.pool, dia.config.disco,
schema.GroupVersionKind{
Group: "",
Version: "v1",
Kind: "Pod",
}, dia.config.currentInputs.GetNamespace())
replicaSetClient, err = clients.ResourceClient(
clients.ReplicaSet, dia.config.currentInputs.GetNamespace(), dia.config.clientSet)
if err != nil {
return nil, nil, nil, errors.Wrapf(err,
"Could not make client to watch Pods associated with Deployment %q",
err = errors.Wrapf(err, "Could not make client to watch ReplicaSets associated with Deployment %q",
dia.config.currentInputs.GetName())
return
}

pvcClient, err = client.FromGVK(dia.config.pool, dia.config.disco,
schema.GroupVersionKind{
Group: "",
Version: "v1",
Kind: "PersistentVolumeClaim",
}, dia.config.currentInputs.GetNamespace())
podClient, err = clients.ResourceClient(
clients.Pod, dia.config.currentInputs.GetNamespace(), dia.config.clientSet)
if err != nil {
return nil, nil, nil, errors.Wrapf(err,
"Could not make client to watch PersistentVolumeClaims associated with Deployment %q",
err = errors.Wrapf(err, "Could not make client to watch Pods associated with Deployment %q",
dia.config.currentInputs.GetName())
return
}
pvcClient, err = clients.ResourceClient(
clients.PersistentVolumeClaim, dia.config.currentInputs.GetNamespace(), dia.config.clientSet)
if err != nil {
err = errors.Wrapf(err, "Could not make client to watch PVCs associated with Deployment %q",
dia.config.currentInputs.GetName())
return
}

return replicaSetClient, podClient, pvcClient, nil
return
}
38 changes: 20 additions & 18 deletions pkg/await/apps_statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@ import (

"github.com/golang/glog"
"github.com/pkg/errors"
"github.com/pulumi/pulumi-kubernetes/pkg/client"
"github.com/pulumi/pulumi-kubernetes/pkg/clients"
"github.com/pulumi/pulumi-kubernetes/pkg/openapi"
"github.com/pulumi/pulumi/pkg/diag"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/watch"
"k8s.io/client-go/dynamic"
)
Expand Down Expand Up @@ -130,18 +129,18 @@ func makeStatefulSetInitAwaiter(c updateAwaitConfig) *statefulsetInitAwaiter {
// 2. The value of `.status.updateRevision` matches `.status.currentRevision`.
func (sia *statefulsetInitAwaiter) Await() error {

podClient, err := sia.makeClients()
statefulSetClient, podClient, err := sia.makeClients()
if err != nil {
return err
}

// Create Deployment watcher.
statefulsetWatcher, err := sia.config.clientForResource.Watch(metav1.ListOptions{})
statefulSetWatcher, err := statefulSetClient.Watch(metav1.ListOptions{})
if err != nil {
return errors.Wrapf(err, "Could not set up watch for StatefulSet object %q",
sia.config.currentInputs.GetName())
}
defer statefulsetWatcher.Stop()
defer statefulSetWatcher.Stop()

// Create Pod watcher.
podWatcher, err := podClient.Watch(metav1.ListOptions{})
Expand All @@ -155,18 +154,18 @@ func (sia *statefulsetInitAwaiter) Await() error {
period := time.NewTicker(10 * time.Second)
defer period.Stop()

return sia.await(statefulsetWatcher, podWatcher, time.After(5*time.Minute), period.C)
return sia.await(statefulSetWatcher, podWatcher, time.After(5*time.Minute), period.C)
}

func (sia *statefulsetInitAwaiter) Read() error {
// Get clients needed to retrieve live versions of relevant Deployments, ReplicaSets, and Pods.
podClient, err := sia.makeClients()
statefulSetClient, podClient, err := sia.makeClients()
if err != nil {
return err
}

// Get live versions of StatefulSet and Pods.
statefulset, err := sia.config.clientForResource.Get(sia.config.currentInputs.GetName(),
statefulset, err := statefulSetClient.Get(sia.config.currentInputs.GetName(),
metav1.GetOptions{})
if err != nil {
// IMPORTANT: Do not wrap this error! If this is a 404, the provider need to know so that it
Expand All @@ -187,7 +186,7 @@ func (sia *statefulsetInitAwaiter) Read() error {
podList = &unstructured.UnstructuredList{Items: []unstructured.Unstructured{}}
}

return sia.read(statefulset, podList.(*unstructured.UnstructuredList))
return sia.read(statefulset, podList)
}

// read is a helper companion to `Read` designed to make it easy to test this module.
Expand Down Expand Up @@ -449,19 +448,22 @@ func (sia *statefulsetInitAwaiter) errorMessages() []string {
}

func (sia *statefulsetInitAwaiter) makeClients() (
podClient dynamic.ResourceInterface, err error,
statefulSetClient, podClient dynamic.ResourceInterface, err error,
) {
podClient, err = client.FromGVK(sia.config.pool, sia.config.disco,
schema.GroupVersionKind{
Group: "",
Version: "v1",
Kind: "Pod",
}, sia.config.currentInputs.GetNamespace())
statefulSetClient, err = clients.ResourceClient(
clients.StatefulSet, sia.config.currentInputs.GetNamespace(), sia.config.clientSet)
if err != nil {
return nil, errors.Wrapf(err,
return nil, nil, errors.Wrapf(err,
"Could not make client to watch StatefulSet %q",
sia.config.currentInputs.GetName())
}
podClient, err = clients.ResourceClient(
clients.Pod, sia.config.currentInputs.GetNamespace(), sia.config.clientSet)
if err != nil {
return nil, nil, errors.Wrapf(err,
"Could not make client to watch Pods associated with StatefulSet %q",
sia.config.currentInputs.GetName())
}

return podClient, nil
return statefulSetClient, podClient, nil
}
Loading