Skip to content

Commit

Permalink
Merge pull request kubernetes#16206 from alvaroaleman/boskos-ctrl-client
Browse files Browse the repository at this point in the history
Boskos: Remove downstream client
  • Loading branch information
k8s-ci-robot committed Feb 11, 2020
2 parents b253986 + ead8695 commit 767a53b
Show file tree
Hide file tree
Showing 25 changed files with 297 additions and 481 deletions.
2 changes: 1 addition & 1 deletion boskos/cleaner/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ go_test(
"//boskos/common:go_default_library",
"//boskos/mason:go_default_library",
"//boskos/ranch:go_default_library",
"//boskos/storage:go_default_library",
"@io_k8s_sigs_controller_runtime//pkg/client/fake:go_default_library",
],
)
6 changes: 4 additions & 2 deletions boskos/cleaner/cleaner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ limitations under the License.
package cleaner

import (
"context"
"testing"
"time"

fakectrlruntimeclient "sigs.k8s.io/controller-runtime/pkg/client/fake"

"k8s.io/test-infra/boskos/common"
"k8s.io/test-infra/boskos/mason"
"k8s.io/test-infra/boskos/ranch"
"k8s.io/test-infra/boskos/storage"
)

const (
Expand All @@ -43,7 +45,7 @@ type fakeBoskos struct {
// Create a fake client
func createFakeBoskos(resources []common.Resource, dlrcs []common.DynamicResourceLifeCycle) (*ranch.Storage, boskosClient, chan releasedResource) {
names := make(chan releasedResource, 100)
s, _ := ranch.NewStorage(storage.NewMemoryStorage(), storage.NewMemoryStorage(), "")
s, _ := ranch.NewStorage(context.Background(), fakectrlruntimeclient.NewFakeClient(), "", "")
r, _ := ranch.NewRanch("", s, testTTL)

for _, lc := range dlrcs {
Expand Down
1 change: 1 addition & 0 deletions boskos/cmd/boskos/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ go_library(
"@com_github_prometheus_client_golang//prometheus:go_default_library",
"@com_github_sirupsen_logrus//:go_default_library",
"@com_github_spf13_viper//:go_default_library",
"@io_k8s_api//core/v1:go_default_library",
],
)

Expand Down
14 changes: 5 additions & 9 deletions boskos/cmd/boskos/boskos.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/prometheus/client_golang/prometheus"
"github.com/sirupsen/logrus"
"github.com/spf13/viper"
corev1 "k8s.io/api/core/v1"

"k8s.io/test-infra/boskos/crds"
"k8s.io/test-infra/boskos/handlers"
Expand All @@ -52,6 +53,7 @@ var (
requestTTL = flag.Duration("request-ttl", defaultRequestTTL, "request TTL before losing priority in the queue")
kubeClientOptions crds.KubernetesClientOptions
logLevel = flag.String("log-level", "info", fmt.Sprintf("Log level is one of %v.", logrus.AllLevels))
namespace = flag.String("namespace", corev1.NamespaceDefault, "namespace to install on")
)

var (
Expand Down Expand Up @@ -88,18 +90,12 @@ func main() {
// main server with the main mux until we're ready
health := pjutil.NewHealth()

rc, err := kubeClientOptions.Client(crds.ResourceType)
client, err := kubeClientOptions.Client()
if err != nil {
logrus.WithError(err).Fatal("unable to create a Resource CRD client")
}
dc, err := kubeClientOptions.Client(crds.DRLCType)
if err != nil {
logrus.WithError(err).Fatal("unable to create a DynamicResourceLifeCycle CRD client")
logrus.WithError(err).Fatal("unable to construct client")
}

resourceStorage := crds.NewCRDStorage(rc)
dRLCStorage := crds.NewCRDStorage(dc)
storage, err := ranch.NewStorage(resourceStorage, dRLCStorage, *storagePath)
storage, err := ranch.NewStorage(interrupts.Context(), client, *namespace, *storagePath)
if err != nil {
logrus.WithError(err).Fatal("failed to create storage")
}
Expand Down
1 change: 1 addition & 0 deletions boskos/cmd/cleaner/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ go_library(
"//boskos/crds:go_default_library",
"//boskos/ranch:go_default_library",
"@com_github_sirupsen_logrus//:go_default_library",
"@io_k8s_api//core/v1:go_default_library",
],
)

Expand Down
12 changes: 7 additions & 5 deletions boskos/cmd/cleaner/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ limitations under the License.
package main

import (
"context"
"flag"
"os"
"os/signal"
"syscall"
"time"

"github.com/sirupsen/logrus"
corev1 "k8s.io/api/core/v1"

"k8s.io/test-infra/boskos/cleaner"
"k8s.io/test-infra/boskos/client"
Expand All @@ -43,6 +45,7 @@ var (
boskosURL string
username string
passwordFile string
namespace string
cleanerCount int
)

Expand All @@ -51,6 +54,7 @@ func init() {
flag.StringVar(&username, "username", "", "Username used to access the Boskos server")
flag.StringVar(&passwordFile, "password-file", "", "The path to password file used to access the Boskos server")
flag.IntVar(&cleanerCount, "cleaner-count", defaultCleanerCount, "Number of threads running cleanup")
flag.StringVar(&namespace, "namespace", corev1.NamespaceDefault, "namespace to install on")
kubeClientOptions.AddFlags(flag.CommandLine)
}

Expand All @@ -59,13 +63,11 @@ func main() {
kubeClientOptions.Validate()

logrus.SetFormatter(&logrus.JSONFormatter{})
dc, err := kubeClientOptions.Client(crds.DRLCType)
kubeClient, err := kubeClientOptions.Client()
if err != nil {
logrus.WithError(err).Fatal("unable to create a Resource CRD client")
logrus.WithError(err).Fatal("failed to construct kube client")
}

resStorage := crds.NewCRDStorage(dc)
st, _ := ranch.NewStorage(nil, resStorage, "")
st, _ := ranch.NewStorage(context.Background(), kubeClient, namespace, "")

logrus.SetFormatter(&logrus.JSONFormatter{})
client, err := client.NewClient(defaultOwner, boskosURL, username, passwordFile)
Expand Down
1 change: 1 addition & 0 deletions boskos/cmd/fake-mason/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ go_library(
"//boskos/mason:go_default_library",
"//boskos/ranch:go_default_library",
"@com_github_sirupsen_logrus//:go_default_library",
"@io_k8s_api//core/v1:go_default_library",
],
)

Expand Down
14 changes: 7 additions & 7 deletions boskos/cmd/fake-mason/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ import (
"syscall"
"time"

"k8s.io/test-infra/boskos/crds"
"k8s.io/test-infra/boskos/ranch"

"github.com/sirupsen/logrus"
corev1 "k8s.io/api/core/v1"

"k8s.io/test-infra/boskos/client"
"k8s.io/test-infra/boskos/common"
"k8s.io/test-infra/boskos/crds"
"k8s.io/test-infra/boskos/mason"
"k8s.io/test-infra/boskos/ranch"
)

const (
Expand All @@ -47,6 +47,7 @@ var (
username = flag.String("username", "", "Username used to access the Boskos server")
passwordFile = flag.String("password-file", "", "The path to password file used to access the Boskos server")
cleanerCount = flag.Int("cleaner-count", defaultCleanerCount, "Number of threads running cleanup")
namespace = flag.String("namespace", corev1.NamespaceDefault, "namespace to install on")
kubeClientOptions crds.KubernetesClientOptions
)

Expand All @@ -68,13 +69,12 @@ func main() {

logrus.SetFormatter(&logrus.JSONFormatter{})

dc, err := kubeClientOptions.Client(crds.DRLCType)
kubeClient, err := kubeClientOptions.Client()
if err != nil {
logrus.WithError(err).Fatal("unable to create a DynamicResourceLifeCycle CRD client")
logrus.WithError(err).Fatal("failed to create kubeClient")
}

dRLCStorage := crds.NewCRDStorage(dc)
st, _ := ranch.NewStorage(nil, dRLCStorage, "")
st, _ := ranch.NewStorage(context.Background(), kubeClient, *namespace, "")

flag.Parse()
logrus.SetFormatter(&logrus.JSONFormatter{})
Expand Down
2 changes: 1 addition & 1 deletion boskos/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ func (ud *UserData) FromMap(m UserDataMap) {
func ItemToResource(i Item) (Resource, error) {
res, ok := i.(Resource)
if !ok {
return Resource{}, fmt.Errorf("cannot construct Resource from received object %v", i)
return Resource{}, fmt.Errorf("expected item to be of type Resource, was %T", i)
}
return res, nil
}
7 changes: 4 additions & 3 deletions boskos/crds/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,25 @@ go_library(
name = "go_default_library",
srcs = [
"client.go",
"crd_storage.go",
"drlc_crd.go",
"register.go",
"resource_crd.go",
],
importpath = "k8s.io/test-infra/boskos/crds",
visibility = ["//visibility:public"],
deps = [
"//boskos/common:go_default_library",
"//boskos/storage:go_default_library",
"@io_k8s_apiextensions_apiserver//pkg/apis/apiextensions/v1beta1:go_default_library",
"@io_k8s_apiextensions_apiserver//pkg/client/clientset/clientset:go_default_library",
"@io_k8s_apimachinery//pkg/api/errors:go_default_library",
"@io_k8s_apimachinery//pkg/apis/meta/v1:go_default_library",
"@io_k8s_apimachinery//pkg/runtime:go_default_library",
"@io_k8s_apimachinery//pkg/runtime/schema:go_default_library",
"@io_k8s_apimachinery//pkg/runtime/serializer:go_default_library",
"@io_k8s_client_go//kubernetes/scheme:go_default_library",
"@io_k8s_client_go//rest:go_default_library",
"@io_k8s_client_go//tools/clientcmd:go_default_library",
"@io_k8s_sigs_controller_runtime//pkg/client:go_default_library",
"@io_k8s_sigs_controller_runtime//pkg/client/fake:go_default_library",
],
)

Expand Down
Loading

0 comments on commit 767a53b

Please sign in to comment.