spotahome / kooper

Kooper is a simple Go library to create Kubernetes operators and controllers.
https://product.spotahome.com/kooper-extending-kubernetes-made-easy-4e1edd884687
Apache License 2.0
506 stars 49 forks source link

go mod fails #113

Closed larytet closed 3 years ago

larytet commented 3 years ago

Hi, I am trying to build the example file https://github.com/spotahome/kooper/blob/master/examples/config-custom-controller/main.go My Dockerfile is

FROM golang:1.15

RUN mkdir /build 
WORKDIR /build
COPY *.go ./
COPY go.mod ./

RUN go mod download
RUN cat go.mod
RUN GOOS=linux CGO_ENABLED=1 GOARCH=amd64 go build -a -o /build ./
# RUN go test -v -failfast ./...

I can not resolve the packages

/go/pkg/mod/k8s.io/client-go@v0.17.4/discovery/discovery_client.go:29:2: module github.com/googleapis/gnostic@latest found (v0.5.4), but does not contain package github.com/googleapis/gnostic/OpenAPIv2
/go/pkg/mod/k8s.io/kube-openapi@v0.0.0-20201113171705-d219536bb9fd/pkg/util/proto/document.go:24:2: case-insensitive import collision: "github.com/googleapis/gnostic/openapiv2" and "github.com/googleapis/gnostic/OpenAPIv2"
/go/pkg/mod/k8s.io/client-go@v0.17.4/kubernetes/scheme/register.go:27:2: module k8s.io/api@latest found (v0.20.4), but does not contain package k8s.io/api/auditregistration/v1alpha1
/go/pkg/mod/k8s.io/client-go@v0.17.4/kubernetes/scheme/register.go:58:2: module k8s.io/api@latest found (v0.20.4), but does not contain package k8s.io/api/settings/v1alpha1

What am I doing wrong? Thanks

larytet commented 3 years ago

I found this https://github.com/kubernetes/client-go/issues/741 k8s.io/api v0.19.0 solved the problem Now the build https://github.com/spotahome/kooper/blob/master/examples/config-custom-controller/main.go of fails

    have ("k8s.io/apimachinery/pkg/apis/meta/v1".ListOptions)
    want (context.Context, "k8s.io/apimachinery/pkg/apis/meta/v1".ListOptions)
./ingress-controller.go:53:41: not enough arguments in call to k8scli.CoreV1().Pods("").Watch
    have ("k8s.io/apimachinery/pkg/apis/meta/v1".ListOptions)
    want (context.Context, "k8s.io/apimachinery/pkg/apis/meta/v1".ListOptions)

Is it Ok to do

diff --git a/ingress-controller.go b/ingress-controller.go
index 861ee60..d62b61b 100644
--- a/ingress-controller.go
+++ b/ingress-controller.go
@@ -25,6 +25,7 @@ import (
 )

 func run() error {
+       ctx := context.Background()
        // Initialize logger.
        logger := kooperlogrus.New(logrus.NewEntry(logrus.New())).
                WithKV(log.KV{"example": "config-custom-controller"})
@@ -47,10 +48,10 @@ func run() error {
        // Create our retriever so the controller knows how to get/listen for pod events.
        retr := controller.MustRetrieverFromListerWatcher(&cache.ListWatch{
                ListFunc: func(options metav1.ListOptions) (runtime.Object, error) {
-                       return k8scli.CoreV1().Pods("").List(options)
+                       return k8scli.CoreV1().Pods("").List(ctx, options)
                },
                WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) {
-                       return k8scli.CoreV1().Pods("").Watch(options)
+                       return k8scli.CoreV1().Pods("").Watch(ctx, options)
                },
        })