Skip to content
This repository has been archived by the owner on May 6, 2022. It is now read-only.

Commit

Permalink
Update deps to k8s 1.18, adjust code after bump
Browse files Browse the repository at this point in the history
  • Loading branch information
mszostok committed May 20, 2020
1 parent 13e3697 commit be8270f
Show file tree
Hide file tree
Showing 2,315 changed files with 263,278 additions and 75,015 deletions.
10 changes: 6 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,10 @@ endif

TYPES_FILES = $(shell find pkg/apis -name types.go)
GO_VERSION ?= 1.13
GOFLAGS =-mod=vendor

# Preserve also user values
GOFLAGS := "$(GOFLAGS) -mod=vendor"
export GOFLAGS
export GO111MODULE=on

ALL_ARCH=amd64 arm arm64 ppc64le s390x
Expand All @@ -80,7 +82,7 @@ endif
BASEIMAGE?=gcr.io/google-containers/debian-base-$(ARCH):v1.0.0

GO_BUILD = env CGO_ENABLED=0 GOOS=$(PLATFORM) GOARCH=$(ARCH) \
go build $(GOFLAGS) -a -tags netgo -installsuffix netgo \
go build -a -tags netgo -installsuffix netgo \
-ldflags '-s -w -X $(SC_PKG)/pkg.VERSION=$(VERSION) $(BUILD_LDFLAGS)'

BASE_PATH = $(ROOT:/src/github.com/kubernetes-sigs/service-catalog/=)
Expand Down Expand Up @@ -168,13 +170,13 @@ generators: $(GENERATORS)
.SECONDEXPANSION:

$(BINDIR)/openapi-gen: $$(shell find vendor/k8s.io/kube-openapi/cmd/openapi-gen vendor/k8s.io/gengo) .init
$(DOCKER_CMD) go build $(GOFLAGS) -o $@ $(SC_PKG)/vendor/k8s.io/kube-openapi/cmd/openapi-gen
$(DOCKER_CMD) go build -o $@ $(SC_PKG)/vendor/k8s.io/kube-openapi/cmd/openapi-gen

# We specify broad dependencies for these generator binaries: each one depends
# on everything under its source tree as well as gengo's. This uses GNU Make's
# secondary expansion feature to pass $* to `find`.
$(BINDIR)/%-gen: $$(shell find vendor/k8s.io/code-generator/cmd/$$*-gen vendor/k8s.io/gengo) .init
$(DOCKER_CMD) go build $(GOFLAGS) -o $@ $(SC_PKG)/vendor/k8s.io/code-generator/cmd/$*-gen
$(DOCKER_CMD) go build -o $@ $(SC_PKG)/vendor/k8s.io/code-generator/cmd/$*-gen

# Regenerate all files if the gen exes changed or any "types.go" files changed
.generate_files: .init generators $(TYPES_FILES)
Expand Down
19 changes: 10 additions & 9 deletions cmd/healthcheck/framework/healthcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package framework

import (
"context"
goflag "flag"
"fmt"
"os"
Expand Down Expand Up @@ -235,7 +236,7 @@ func (h *HealthCheck) createInstance() error {
},
}
operationStartTime := time.Now()
instance, err = h.serviceCatalogClientSet.ServicecatalogV1beta1().ServiceInstances(h.namespace.Name).Create(instance)
instance, err = h.serviceCatalogClientSet.ServicecatalogV1beta1().ServiceInstances(h.namespace.Name).Create(context.Background(), instance, metav1.CreateOptions{})
if err != nil {
return h.setError("error creating instance: %v", err.Error())
}
Expand All @@ -259,7 +260,7 @@ func (h *HealthCheck) createInstance() error {
ReportOperationCompleted("create_instance", operationStartTime)

klog.V(4).Info("Verifing references are resolved")
sc, err := h.serviceCatalogClientSet.ServicecatalogV1beta1().ServiceInstances(h.namespace.Name).Get(h.instanceName, metav1.GetOptions{})
sc, err := h.serviceCatalogClientSet.ServicecatalogV1beta1().ServiceInstances(h.namespace.Name).Get(context.Background(), h.instanceName, metav1.GetOptions{})
if err != nil {
return h.setError("error getting instance: %v", err.Error())
}
Expand Down Expand Up @@ -300,7 +301,7 @@ func (h *HealthCheck) createBinding() error {
},
}
operationStartTime := time.Now()
binding, err := h.serviceCatalogClientSet.ServicecatalogV1beta1().ServiceBindings(h.namespace.Name).Create(binding)
binding, err := h.serviceCatalogClientSet.ServicecatalogV1beta1().ServiceBindings(h.namespace.Name).Create(context.Background(), binding, metav1.CreateOptions{})
if err != nil {
return h.setError("Error creating binding: %v", err.Error())
}
Expand All @@ -323,7 +324,7 @@ func (h *HealthCheck) createBinding() error {
ReportOperationCompleted("binding_ready", operationStartTime)

klog.V(4).Info("Validating that a secret was created after binding")
_, err = h.kubeClientSet.CoreV1().Secrets(h.namespace.Name).Get("my-secret", metav1.GetOptions{})
_, err = h.kubeClientSet.CoreV1().Secrets(h.namespace.Name).Get(context.Background(), "my-secret", metav1.GetOptions{})
if err != nil {
return h.setError("Error getting secret: %v", err.Error())
}
Expand All @@ -339,7 +340,7 @@ func (h *HealthCheck) deprovision() error {
}
klog.V(4).Info("Deleting the ServiceBinding.")
operationStartTime := time.Now()
err := h.serviceCatalogClientSet.ServicecatalogV1beta1().ServiceBindings(h.namespace.Name).Delete(h.bindingName, nil)
err := h.serviceCatalogClientSet.ServicecatalogV1beta1().ServiceBindings(h.namespace.Name).Delete(context.Background(), h.bindingName, metav1.DeleteOptions{})
if err != nil {
return h.setError("error deleting binding: %v", err.Error())
}
Expand All @@ -352,15 +353,15 @@ func (h *HealthCheck) deprovision() error {
ReportOperationCompleted("binding_deleted", operationStartTime)

klog.V(4).Info("Verifying that the secret was deleted after deleting the binding")
_, err = h.kubeClientSet.CoreV1().Secrets(h.namespace.Name).Get("my-secret", metav1.GetOptions{})
_, err = h.kubeClientSet.CoreV1().Secrets(h.namespace.Name).Get(context.Background(), "my-secret", metav1.GetOptions{})
if err == nil {
return h.setError("secret not deleted")
}

// Deprovisioning the ServiceInstance
klog.V(4).Info("Deleting the ServiceInstance")
operationStartTime = time.Now()
err = h.serviceCatalogClientSet.ServicecatalogV1beta1().ServiceInstances(h.namespace.Name).Delete(h.instanceName, nil)
err = h.serviceCatalogClientSet.ServicecatalogV1beta1().ServiceInstances(h.namespace.Name).Delete(context.Background(), h.instanceName, metav1.DeleteOptions{})
if err != nil {
return h.setError("error deleting instance: %v", err.Error())
}
Expand All @@ -378,8 +379,8 @@ func (h *HealthCheck) deprovision() error {
func (h *HealthCheck) cleanup() {
if h.frameworkError != nil && h.namespace != nil {
klog.V(4).Infof("Cleaning up. Deleting the binding, instance and test namespace %v", h.namespace.Name)
h.serviceCatalogClientSet.ServicecatalogV1beta1().ServiceBindings(h.namespace.Name).Delete(h.bindingName, nil)
h.serviceCatalogClientSet.ServicecatalogV1beta1().ServiceInstances(h.namespace.Name).Delete(h.instanceName, nil)
h.serviceCatalogClientSet.ServicecatalogV1beta1().ServiceBindings(h.namespace.Name).Delete(context.Background(), h.bindingName, metav1.DeleteOptions{})
h.serviceCatalogClientSet.ServicecatalogV1beta1().ServiceInstances(h.namespace.Name).Delete(context.Background(), h.instanceName, metav1.DeleteOptions{})
DeleteKubeNamespace(h.kubeClientSet, h.namespace.Name)
h.namespace = nil
}
Expand Down
7 changes: 4 additions & 3 deletions cmd/healthcheck/framework/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package framework

import (
"context"
"fmt"
"time"

Expand Down Expand Up @@ -76,7 +77,7 @@ func CreateKubeNamespace(c kubernetes.Interface) (*corev1.Namespace, error) {
var got *corev1.Namespace
err := wait.PollImmediate(poll, defaultTimeout, func() (bool, error) {
var err error
got, err = c.CoreV1().Namespaces().Create(ns)
got, err = c.CoreV1().Namespaces().Create(context.Background(), ns, metav1.CreateOptions{})
if err != nil {
klog.Errorf("Unexpected error while creating namespace: %v", err)
return false, err
Expand All @@ -91,7 +92,7 @@ func CreateKubeNamespace(c kubernetes.Interface) (*corev1.Namespace, error) {

// DeleteKubeNamespace deletes the specified K8s namespace
func DeleteKubeNamespace(c kubernetes.Interface, namespace string) error {
return c.CoreV1().Namespaces().Delete(namespace, nil)
return c.CoreV1().Namespaces().Delete(context.Background(), namespace, metav1.DeleteOptions{})
}

// WaitForEndpoint waits for 'defaultTimeout' interval for an endpoint to be available
Expand All @@ -101,7 +102,7 @@ func WaitForEndpoint(c kubernetes.Interface, namespace, name string) error {

func endpointAvailable(c kubernetes.Interface, namespace, name string) wait.ConditionFunc {
return func() (bool, error) {
endpoint, err := c.CoreV1().Endpoints(namespace).Get(name, metav1.GetOptions{})
endpoint, err := c.CoreV1().Endpoints(namespace).Get(context.Background(), name, metav1.GetOptions{})
if err != nil {
if apierrs.IsNotFound(err) {
return false, nil
Expand Down
13 changes: 7 additions & 6 deletions cmd/svcat/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ import (
"fmt"
"os"

"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/klog"
"k8s.io/kubectl/pkg/pluginutils"

"github.com/kubernetes-sigs/service-catalog/cmd/svcat/binding"
"github.com/kubernetes-sigs/service-catalog/cmd/svcat/broker"
"github.com/kubernetes-sigs/service-catalog/cmd/svcat/browsing"
Expand All @@ -42,7 +37,11 @@ import (
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/spf13/viper"
"k8s.io/cli-runtime/pkg/genericclioptions"
k8sclient "k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/klog"
)

// These are build-time values, set during an official release
Expand Down Expand Up @@ -216,7 +215,9 @@ func getClients(kubeConfig, kubeContext string) (k8sClient k8sclient.Interface,
var config clientcmd.ClientConfig

if plugin.IsPlugin() {
restConfig, config, err = pluginutils.InitClientAndConfig()
configFlags := genericclioptions.NewConfigFlags(true)
config = configFlags.ToRawKubeConfigLoader()
restConfig, err = configFlags.ToRESTConfig()
if err != nil {
return nil, nil, "", fmt.Errorf("could not get Kubernetes config from kubectl plugin context: %s", err)
}
Expand Down
10 changes: 7 additions & 3 deletions cmd/svcat/svcat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ func TestGetSvcatWithNamespacedBrokerFeatureDisabled(t *testing.T) {
CommonServicePlanSpec: v1beta1.CommonServicePlanSpec{
ExternalName: "my-cluster-plan",
},
ClusterServiceClassRef: v1beta1.ClusterObjectReference{
Name: "my-cluster-class",
},
},
},
}
Expand Down Expand Up @@ -549,17 +552,18 @@ func executeCommand(t *testing.T, cmd string, continueOnErr bool) string {
// executeCommand runs a svcat command against a fake k8s api,
// returning the cli output.
func executeFakeCommand(t *testing.T, cmd string, fakeContext *command.Context, continueOnErr bool) string {
t.Helper()
// Setup the svcat command
svcat, _, err := buildCommand(cmd, fakeContext, "")
cli, _, err := buildCommand(cmd, fakeContext, "")
if err != nil {
t.Fatalf("%+v", err)
}

// Capture all output: stderr and stdout
output := &bytes.Buffer{}
svcat.SetOutput(output)
cli.SetOutput(output)

err = svcat.Execute()
err = cli.Execute()
if err != nil && !continueOnErr {
t.Fatalf("%+v", err)
}
Expand Down
Loading

0 comments on commit be8270f

Please sign in to comment.