From 9a8a99e8b99cd004cf2510f08249218bb978df1d Mon Sep 17 00:00:00 2001 From: Yisui Hu Date: Wed, 13 Mar 2019 16:41:20 -0700 Subject: [PATCH] add tenant-controller code skeleton --- .envrc | 2 + .gitignore | 4 + CONTRIBUTING.md | 5 +- README.md | 4 + poc/README.md | 53 ++++++ poc/tenant-controller/README.md | 3 + poc/tenant-controller/cmd/tenant-ctl/main.go | 80 ++++++++ poc/tenant-controller/go.mod | 28 +++ poc/tenant-controller/go.sum | 65 +++++++ .../pkg/apis/tenants/register.go | 17 ++ .../pkg/apis/tenants/v1alpha1/doc.go | 16 ++ .../pkg/apis/tenants/v1alpha1/register.go | 48 +++++ .../pkg/apis/tenants/v1alpha1/types.go | 106 +++++++++++ .../tenants/v1alpha1/zz_generated.deepcopy.go | 140 ++++++++++++++ .../tenants/clientset/v1alpha1/clientset.go | 85 +++++++++ .../clients/tenants/clientset/v1alpha1/doc.go | 15 ++ .../v1alpha1/fake/clientset_generated.go | 72 +++++++ .../tenants/clientset/v1alpha1/fake/doc.go | 15 ++ .../clientset/v1alpha1/fake/register.go | 51 +++++ .../tenants/clientset/v1alpha1/scheme/doc.go | 15 ++ .../clientset/v1alpha1/scheme/register.go | 51 +++++ .../v1alpha1/typed/tenants/v1alpha1/doc.go | 15 ++ .../typed/tenants/v1alpha1/fake/doc.go | 15 ++ .../tenants/v1alpha1/fake/fake_tenant.go | 126 +++++++++++++ .../v1alpha1/fake/fake_tenants_client.go | 35 ++++ .../tenants/v1alpha1/generated_expansion.go | 16 ++ .../v1alpha1/typed/tenants/v1alpha1/tenant.go | 175 ++++++++++++++++++ .../typed/tenants/v1alpha1/tenants_client.go | 85 +++++++++ .../informers/externalversions/factory.go | 175 ++++++++++++++++++ .../informers/externalversions/generic.go | 57 ++++++ .../internalinterfaces/factory_interfaces.go | 35 ++++ .../externalversions/tenants/interface.go | 41 ++++ .../tenants/v1alpha1/interface.go | 40 ++++ .../tenants/v1alpha1/tenant.go | 83 +++++++++ .../tenants/v1alpha1/expansion_generated.go | 18 ++ .../listers/tenants/v1alpha1/tenant.go | 60 ++++++ .../pkg/controllers/tenants/controller.go | 73 ++++++++ tools/bin/devtk | 20 ++ tools/lib/devtk/cmd-build.sh | 63 +++++++ tools/lib/devtk/cmd-codegen.sh | 59 ++++++ tools/lib/devtk/cmd-setup.sh | 30 +++ tools/lib/functions.sh | 34 ++++ tools/lib/header.go.txt | 10 + 43 files changed, 2136 insertions(+), 4 deletions(-) create mode 100644 .envrc create mode 100644 .gitignore create mode 100644 poc/README.md create mode 100644 poc/tenant-controller/README.md create mode 100644 poc/tenant-controller/cmd/tenant-ctl/main.go create mode 100644 poc/tenant-controller/go.mod create mode 100644 poc/tenant-controller/go.sum create mode 100644 poc/tenant-controller/pkg/apis/tenants/register.go create mode 100644 poc/tenant-controller/pkg/apis/tenants/v1alpha1/doc.go create mode 100644 poc/tenant-controller/pkg/apis/tenants/v1alpha1/register.go create mode 100644 poc/tenant-controller/pkg/apis/tenants/v1alpha1/types.go create mode 100644 poc/tenant-controller/pkg/apis/tenants/v1alpha1/zz_generated.deepcopy.go create mode 100644 poc/tenant-controller/pkg/clients/tenants/clientset/v1alpha1/clientset.go create mode 100644 poc/tenant-controller/pkg/clients/tenants/clientset/v1alpha1/doc.go create mode 100644 poc/tenant-controller/pkg/clients/tenants/clientset/v1alpha1/fake/clientset_generated.go create mode 100644 poc/tenant-controller/pkg/clients/tenants/clientset/v1alpha1/fake/doc.go create mode 100644 poc/tenant-controller/pkg/clients/tenants/clientset/v1alpha1/fake/register.go create mode 100644 poc/tenant-controller/pkg/clients/tenants/clientset/v1alpha1/scheme/doc.go create mode 100644 poc/tenant-controller/pkg/clients/tenants/clientset/v1alpha1/scheme/register.go create mode 100644 poc/tenant-controller/pkg/clients/tenants/clientset/v1alpha1/typed/tenants/v1alpha1/doc.go create mode 100644 poc/tenant-controller/pkg/clients/tenants/clientset/v1alpha1/typed/tenants/v1alpha1/fake/doc.go create mode 100644 poc/tenant-controller/pkg/clients/tenants/clientset/v1alpha1/typed/tenants/v1alpha1/fake/fake_tenant.go create mode 100644 poc/tenant-controller/pkg/clients/tenants/clientset/v1alpha1/typed/tenants/v1alpha1/fake/fake_tenants_client.go create mode 100644 poc/tenant-controller/pkg/clients/tenants/clientset/v1alpha1/typed/tenants/v1alpha1/generated_expansion.go create mode 100644 poc/tenant-controller/pkg/clients/tenants/clientset/v1alpha1/typed/tenants/v1alpha1/tenant.go create mode 100644 poc/tenant-controller/pkg/clients/tenants/clientset/v1alpha1/typed/tenants/v1alpha1/tenants_client.go create mode 100644 poc/tenant-controller/pkg/clients/tenants/informers/externalversions/factory.go create mode 100644 poc/tenant-controller/pkg/clients/tenants/informers/externalversions/generic.go create mode 100644 poc/tenant-controller/pkg/clients/tenants/informers/externalversions/internalinterfaces/factory_interfaces.go create mode 100644 poc/tenant-controller/pkg/clients/tenants/informers/externalversions/tenants/interface.go create mode 100644 poc/tenant-controller/pkg/clients/tenants/informers/externalversions/tenants/v1alpha1/interface.go create mode 100644 poc/tenant-controller/pkg/clients/tenants/informers/externalversions/tenants/v1alpha1/tenant.go create mode 100644 poc/tenant-controller/pkg/clients/tenants/listers/tenants/v1alpha1/expansion_generated.go create mode 100644 poc/tenant-controller/pkg/clients/tenants/listers/tenants/v1alpha1/tenant.go create mode 100644 poc/tenant-controller/pkg/controllers/tenants/controller.go create mode 100755 tools/bin/devtk create mode 100644 tools/lib/devtk/cmd-build.sh create mode 100644 tools/lib/devtk/cmd-codegen.sh create mode 100644 tools/lib/devtk/cmd-setup.sh create mode 100644 tools/lib/functions.sh create mode 100644 tools/lib/header.go.txt diff --git a/.envrc b/.envrc new file mode 100644 index 000000000..df8a92d19 --- /dev/null +++ b/.envrc @@ -0,0 +1,2 @@ +export GOPATH=`pwd`/tmp/go +export PATH="`pwd`/tools/bin:$GOPATH/bin:$PATH" diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..82cd8a1e3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +/tmp +/log +/out +/bin diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 006fdad92..356199110 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -8,10 +8,7 @@ _As contributors and maintainers of this project, and in the interest of fosteri We have full documentation on how to get started contributing here: - - +- [PoC Development Guide](poc/README.md) Development Guide for contributing PoC code in this repository - [Contributor License Agreement](https://git.k8s.io/community/CLA.md) Kubernetes projects require that you sign a Contributor License Agreement (CLA) before we can accept your pull requests - [Kubernetes Contributor Guide](https://git.k8s.io/community/contributors/guide) - Main contributor documentation, or you can just jump directly to the [contributing section](https://git.k8s.io/community/contributors/guide#contributing) - [Contributor Cheat Sheet](https://git.k8s.io/community/contributors/guide/contributor-cheatsheet.md) - Common resources for existing developers diff --git a/README.md b/README.md index 1cc1c67a8..43a9b4477 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,10 @@ You can reach the maintainers of this project at: - [Slack channel](https://kubernetes.slack.com/messages/wg-multitenancy) - [Mailing list](https://groups.google.com/forum/#!forum/kubernetes-wg-multitenancy) +### PoC directory + +The `poc` directory contains all _proof-of-concept_ code which is not supported. + ### Code of conduct Participation in the Kubernetes community is governed by the [Kubernetes Code of Conduct](code-of-conduct.md). diff --git a/poc/README.md b/poc/README.md new file mode 100644 index 000000000..ace7e13ff --- /dev/null +++ b/poc/README.md @@ -0,0 +1,53 @@ +# PoC Development Guide + +The Development Guide for contributing PoC (Proof-Of-Concept) code in this repository. + +## Development Environment + +### Environment Variables + +[direnv](https://direnv.net/) is recommended for automated environment population. +With _direnv_, `cd` into the directory of the repository, +the environment variables gets setup automatically. +Without _direnv_, `cd` into the directory of the respository and `source .envrc` will +do the same work. + +### Tools + +Install pre-requisites: + +- [Go](https://golang.org): `1.11.4` or above + +After environment variables are populated, do one-time setup of tools using: + +``` +devtk setup +``` + +## Development Toolkit + +A single entry for most of development work is `devtk` command. +To add new commandlet, create `cmd-COMMAND.sh` in `tools/lib/devkit/`. + +The current commands: + +#### One-time Setup + +``` +devkit setup +``` + +#### Generate Code + +``` +devkit codegen # generate code for all poc projects +devkit codegen tenant-controller # generate code for tenant-controller project only +``` + +#### Build Binaries + +``` +devkit build # build all binaries from all projects +devkit build tenants-ctl # build the specified binary +devkit build tenant-controller/tenants-ctl # build the specified binary within project explicitly specified +``` diff --git a/poc/tenant-controller/README.md b/poc/tenant-controller/README.md new file mode 100644 index 000000000..4d91f1499 --- /dev/null +++ b/poc/tenant-controller/README.md @@ -0,0 +1,3 @@ +# Tenant Controller + +This is PoC for tenant management using CRDs. diff --git a/poc/tenant-controller/cmd/tenant-ctl/main.go b/poc/tenant-controller/cmd/tenant-ctl/main.go new file mode 100644 index 000000000..579c89611 --- /dev/null +++ b/poc/tenant-controller/cmd/tenant-ctl/main.go @@ -0,0 +1,80 @@ +// Copyright 2017 The Kubernetes Authors. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package main + +import ( + "context" + "flag" + "os" + "os/signal" + "syscall" + "time" + + "github.com/golang/glog" + "k8s.io/client-go/tools/clientcmd" + tenantsclient "sigs.k8s.io/multi-tenancy/poc/tenant-controller/pkg/clients/tenants/clientset/v1alpha1" + tenantsinformers "sigs.k8s.io/multi-tenancy/poc/tenant-controller/pkg/clients/tenants/informers/externalversions" + tenants "sigs.k8s.io/multi-tenancy/poc/tenant-controller/pkg/controllers/tenants" +) + +var ( + masterURL string + kubeconfig = os.Getenv("KUBECONFIG") +) + +const ( + defaultResyncInterval = time.Duration(0) +) + +func init() { + flag.StringVar(&masterURL, "master", masterURL, "The URL of the Kubernetes API server.") + flag.StringVar(&kubeconfig, "kubeconfig", kubeconfig, "Path to kubeconfig file.") +} + +func main() { + flag.Parse() + + cfg, err := clientcmd.BuildConfigFromFlags(masterURL, kubeconfig) + if err != nil { + glog.Fatalf("building kubeconfig: %v", err) + } + + tenantsClient, err := tenantsclient.NewForConfig(cfg) + if err != nil { + glog.Fatalf("create tenants client: %v", err) + } + + tenantsInformerFactory := tenantsinformers.NewSharedInformerFactory(tenantsClient, defaultResyncInterval) + + tenantsCtl := tenants.NewController(tenantsClient, tenantsInformerFactory) + + daemonCtx, cancelFn := context.WithCancel(context.TODO()) + sigCh, errCh := make(chan os.Signal, 1), make(chan error, 1) + signal.Notify(sigCh, os.Interrupt, syscall.SIGTERM) + go func() { + <-sigCh + // the first signal notifies cancels the context. + cancelFn() + <-sigCh + // the second signal forcibly terminate the process. + os.Exit(1) + }() + + go tenantsInformerFactory.Start(daemonCtx.Done()) + go func() { + errCh <- tenantsCtl.Run(daemonCtx) + }() + + if err = <-errCh; err != nil { + glog.Fatalf("controller error: %v", err) + } +} diff --git a/poc/tenant-controller/go.mod b/poc/tenant-controller/go.mod new file mode 100644 index 000000000..24ee0f3d5 --- /dev/null +++ b/poc/tenant-controller/go.mod @@ -0,0 +1,28 @@ +module sigs.k8s.io/multi-tenancy/poc/tenant-controller + +require ( + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/gogo/protobuf v1.2.1 // indirect + github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b + github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c // indirect + github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf // indirect + github.com/googleapis/gnostic v0.2.0 // indirect + github.com/gregjones/httpcache v0.0.0-20190212212710-3befbb6ad0cc // indirect + github.com/hashicorp/golang-lru v0.5.1 // indirect + github.com/imdario/mergo v0.3.7 // indirect + github.com/json-iterator/go v1.1.6 // indirect + github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect + github.com/modern-go/reflect2 v1.0.1 // indirect + github.com/peterbourgon/diskv v2.0.1+incompatible // indirect + github.com/spf13/pflag v1.0.3 // indirect + golang.org/x/net v0.0.0-20190313082753-5c2c250b6a70 // indirect + golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421 // indirect + golang.org/x/time v0.0.0-20190308202827-9d24e82272b4 // indirect + gopkg.in/inf.v0 v0.9.1 // indirect + gopkg.in/yaml.v2 v2.2.2 // indirect + k8s.io/api v0.0.0-20181204000039-89a74a8d264d + k8s.io/apimachinery v0.0.0-20181127025237-2b1284ed4c93 + k8s.io/client-go v10.0.0+incompatible + k8s.io/klog v0.2.0 // indirect + sigs.k8s.io/yaml v1.1.0 // indirect +) diff --git a/poc/tenant-controller/go.sum b/poc/tenant-controller/go.sum new file mode 100644 index 000000000..da744d15f --- /dev/null +++ b/poc/tenant-controller/go.sum @@ -0,0 +1,65 @@ +cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/gogo/protobuf v1.2.1 h1:/s5zKNz0uPFCZ5hddgPdo2TK2TVrUNMn0OOX8/aZMTE= +github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4= +github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58= +github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= +github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c h1:964Od4U6p2jUkFxvCydnIczKteheJEzHRToSGK3Bnlw= +github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= +github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf h1:+RRA9JqSOZFfKrOeqr2z77+8R2RKyh8PG66dcu1V0ck= +github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf/go.mod h1:HP5RmnzzSNb993RKQDq4+1A4ia9nllfqcQFTQJedwGI= +github.com/googleapis/gnostic v0.2.0 h1:l6N3VoaVzTncYYW+9yOz2LJJammFZGBO13sqgEhpy9g= +github.com/googleapis/gnostic v0.2.0/go.mod h1:sJBsCZ4ayReDTBIg8b9dl28c5xFWyhBTVRp3pOg5EKY= +github.com/gregjones/httpcache v0.0.0-20190212212710-3befbb6ad0cc h1:f8eY6cV/x1x+HLjOp4r72s/31/V2aTUtg5oKRRPf8/Q= +github.com/gregjones/httpcache v0.0.0-20190212212710-3befbb6ad0cc/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA= +github.com/hashicorp/golang-lru v0.5.1 h1:0hERBMJE1eitiLkihrMvRVBYAkpHzc/J3QdDN+dAcgU= +github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= +github.com/imdario/mergo v0.3.7 h1:Y+UAYTZ7gDEuOfhxKWy+dvb5dRQ6rJjFSdX2HZY1/gI= +github.com/imdario/mergo v0.3.7/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA= +github.com/json-iterator/go v1.1.6 h1:MrUvLMLTMxbqFJ9kzlvat/rYZqZnW3u4wkLzWTaFwKs= +github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= +github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= +github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/reflect2 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9AWI= +github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= +github.com/peterbourgon/diskv v2.0.1+incompatible h1:UBdAOUP5p4RWqPBg048CAvpKN+vxiaj6gdUUzhl4XmI= +github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod h1:uqqh8zWWbv1HBMNONnaR/tNboyR3/BZd58JJSHlUSCU= +github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg= +github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 h1:VklqNMn3ovrHsnt90PveolxSbWFaJdECFbxSq0Mqo2M= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190313082753-5c2c250b6a70 h1:0OwHPyvXNyZS9VW4XXoGkWOwhrMN52Y4n/gSxvJOgj0= +golang.org/x/net v0.0.0-20190313082753-5c2c250b6a70/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421 h1:Wo7BWFiOk0QRFMLYMqJGFMd9CgUAcGx7V+qEg/h5IBI= +golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a h1:1BGLXjeY4akVXGgbC9HugT3Jv3hCI0z56oJR5vAMgBU= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/time v0.0.0-20190308202827-9d24e82272b4 h1:SvFZT6jyqRaOeXpc5h/JSfZenJ2O330aBsf7JfSUXmQ= +golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc= +gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw= +gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +k8s.io/api v0.0.0-20181204000039-89a74a8d264d h1:HQoGWsWUe/FmRcX9BU440AAMnzBFEf+DBo4nbkQlNzs= +k8s.io/api v0.0.0-20181204000039-89a74a8d264d/go.mod h1:iuAfoD4hCxJ8Onx9kaTIt30j7jUFS00AXQi6QMi99vA= +k8s.io/apimachinery v0.0.0-20181127025237-2b1284ed4c93 h1:tT6oQBi0qwLbbZSfDkdIsb23EwaLY85hoAV4SpXfdao= +k8s.io/apimachinery v0.0.0-20181127025237-2b1284ed4c93/go.mod h1:ccL7Eh7zubPUSh9A3USN90/OzHNSVN6zxzde07TDCL0= +k8s.io/client-go v10.0.0+incompatible h1:F1IqCqw7oMBzDkqlcBymRq1450wD0eNqLE9jzUrIi34= +k8s.io/client-go v10.0.0+incompatible/go.mod h1:7vJpHMYJwNQCWgzmNV+VYUl1zCObLyodBc8nIyt8L5s= +k8s.io/klog v0.2.0 h1:0ElL0OHzF3N+OhoJTL0uca20SxtYt4X4+bzHeqrB83c= +k8s.io/klog v0.2.0/go.mod h1:Gq+BEi5rUBO/HRz0bTSXDUcqjScdoY3a9IHpCEIOOfk= +sigs.k8s.io/yaml v1.1.0 h1:4A07+ZFc2wgJwo8YNlQpr1rVlgUDlxXHhPJciaPY5gs= +sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o= diff --git a/poc/tenant-controller/pkg/apis/tenants/register.go b/poc/tenant-controller/pkg/apis/tenants/register.go new file mode 100644 index 000000000..9f36ae1dc --- /dev/null +++ b/poc/tenant-controller/pkg/apis/tenants/register.go @@ -0,0 +1,17 @@ +// Copyright 2017 The Kubernetes Authors. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package tenants + +const ( + // GroupName defines the API group + GroupName = "tenants.k8s.io" +) diff --git a/poc/tenant-controller/pkg/apis/tenants/v1alpha1/doc.go b/poc/tenant-controller/pkg/apis/tenants/v1alpha1/doc.go new file mode 100644 index 000000000..849934ce6 --- /dev/null +++ b/poc/tenant-controller/pkg/apis/tenants/v1alpha1/doc.go @@ -0,0 +1,16 @@ +// Copyright 2017 The Kubernetes Authors. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// +k8s:deepcopy-gen=package + +// Package v1alpha1 is the v1alpha1 version of the API. +// +groupName=tenants.k8s.io +package v1alpha1 diff --git a/poc/tenant-controller/pkg/apis/tenants/v1alpha1/register.go b/poc/tenant-controller/pkg/apis/tenants/v1alpha1/register.go new file mode 100644 index 000000000..215b9fec8 --- /dev/null +++ b/poc/tenant-controller/pkg/apis/tenants/v1alpha1/register.go @@ -0,0 +1,48 @@ +// Copyright 2017 The Kubernetes Authors. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package v1alpha1 + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + k8srt "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/runtime/schema" + + api "sigs.k8s.io/multi-tenancy/poc/tenant-controller/pkg/apis/tenants" +) + +// SchemeGroupVersion is group version used to register these objects. +var SchemeGroupVersion = schema.GroupVersion{Group: api.GroupName, Version: "v1alpha1"} + +// Kind takes an unqualified kind and returns back a Group qualified GroupKind. +func Kind(kind string) schema.GroupKind { + return SchemeGroupVersion.WithKind(kind).GroupKind() +} + +// Resource takes an unqualified resource and returns a Group qualified GroupResource. +func Resource(resource string) schema.GroupResource { + return SchemeGroupVersion.WithResource(resource).GroupResource() +} + +var ( + // SchemeBuilder is the exported SchemeBuilder for the API. + SchemeBuilder = k8srt.NewSchemeBuilder(addKnownTypes) + // AddToScheme is the exported AddToScheme func for the API. + AddToScheme = SchemeBuilder.AddToScheme +) + +func addKnownTypes(scheme *k8srt.Scheme) error { + scheme.AddKnownTypes(SchemeGroupVersion, + &Tenant{}, + ) + metav1.AddToGroupVersion(scheme, SchemeGroupVersion) + return nil +} diff --git a/poc/tenant-controller/pkg/apis/tenants/v1alpha1/types.go b/poc/tenant-controller/pkg/apis/tenants/v1alpha1/types.go new file mode 100644 index 000000000..9ff8fa77b --- /dev/null +++ b/poc/tenant-controller/pkg/apis/tenants/v1alpha1/types.go @@ -0,0 +1,106 @@ +// Copyright 2017 The Kubernetes Authors. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package v1alpha1 + +import ( + rbacv1 "k8s.io/api/rbac/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +// +genclient +// +genclient:nonNamespaced +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +// Tenant is the resource represents a group of users belonging to the same tenant. +// A Tenant is a grouping concept of resources belong to a group of users (the tenant). +// Under a tenant, one or more namespaces are created. +// The OwerReferences in namespace resource will point to this Tenant resource, so +// once the Tenant resource is deleted, the namespaces will be garbage collected. +// Beyond this, the following labels are proposed to be associated with namespaces: +// tenants.k8s.io/tenant= +type Tenant struct { + metav1.TypeMeta `json:",inline"` + // ObjectMeta is standard object metadata + // +optional + metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"` + + // Spec is the details of the tenant. + // +optional + Spec TenantSpec `json:"spec" protobuf:"bytes,2,opt,name=spec"` + + // Status is the status of the tenant. + // +optional + Status TenantStatus `json:"status" protobuf:"bytes,3,opt,name=status"` +} + +// TenantSpec defines the spec of a tenant resource. +// The Tenant controller will use the list of Namespaces here as the source of truth +// to reconciliate the actual namespaces belong to the tenant. +// Updating the namespace list here will trigger the reconciliation of namespaces. +type TenantSpec struct { + // Admins are the identities with admin privilege in namespaces. + // +optional + Admins []rbacv1.Subject `json:"admins"` + + // Namespaces are the namespaces created for the tenant. + // +optional + Namespaces []TenantNamespace `json:"namespaces"` +} + +// TenantStatus defines the status of a tenant resource. +type TenantStatus struct { + // Phase indicates if the tenant is Pending, Creating, Active or Terminating. + // +optional + Phase TenantPhase `json:"phase,omitempty" protobuf:"bytes,1,opt,name=phase,casttype=TenantPhase"` + + // Message provides human-readable information of current status. + // +optional + Message string `json:"message,omitempty" protobuf:"bytes,2,opt,name=message"` + + // Reason is a brief CamelCase string describing the status. + // +optional + Reason string `json:"reason,omitempty" protobuf:"bytes,3,opt,name=reason"` +} + +// TenantNamespace defines the namespaces belonging to this tenant. +type TenantNamespace struct { + Name string `json:"name"` + Template string `json:"template"` +} + +// TenantPhase defines the phase of tenant status. +type TenantPhase string + +// Known tenant phases. +const ( + // TenantPending means the tenant is going to be created, but not happening yet. + // This is set right after the tenant is created. + TenantPending TenantPhase = "Pending" + // TenantCreating means tenant is being created. + TenantCreating TenantPhase = "Creating" + // TenantActive means tenant is ready and being used. + TenantActive TenantPhase = "Active" + // TenantTerminating means tenant is being removed. + TenantTerminating TenantPhase = "Terminating" +) + +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +type TenantList struct { + metav1.TypeMeta `json:",inline"` + // ObjectMeta is standard object metadata + // +optional + metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"` + + // Items are list of Tenant objects. + Items []Tenant `json:"items" protobuf:"bytes,2,rep,name=items` +} diff --git a/poc/tenant-controller/pkg/apis/tenants/v1alpha1/zz_generated.deepcopy.go b/poc/tenant-controller/pkg/apis/tenants/v1alpha1/zz_generated.deepcopy.go new file mode 100644 index 000000000..0d901a451 --- /dev/null +++ b/poc/tenant-controller/pkg/apis/tenants/v1alpha1/zz_generated.deepcopy.go @@ -0,0 +1,140 @@ +// +build !ignore_autogenerated + +// Copyright 2017 The Kubernetes Authors. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by deepcopy-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + v1 "k8s.io/api/rbac/v1" + runtime "k8s.io/apimachinery/pkg/runtime" +) + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Tenant) DeepCopyInto(out *Tenant) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Spec.DeepCopyInto(&out.Spec) + out.Status = in.Status + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Tenant. +func (in *Tenant) DeepCopy() *Tenant { + if in == nil { + return nil + } + out := new(Tenant) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *Tenant) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *TenantList) DeepCopyInto(out *TenantList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]Tenant, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TenantList. +func (in *TenantList) DeepCopy() *TenantList { + if in == nil { + return nil + } + out := new(TenantList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *TenantList) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *TenantNamespace) DeepCopyInto(out *TenantNamespace) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TenantNamespace. +func (in *TenantNamespace) DeepCopy() *TenantNamespace { + if in == nil { + return nil + } + out := new(TenantNamespace) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *TenantSpec) DeepCopyInto(out *TenantSpec) { + *out = *in + if in.Admins != nil { + in, out := &in.Admins, &out.Admins + *out = make([]v1.Subject, len(*in)) + copy(*out, *in) + } + if in.Namespaces != nil { + in, out := &in.Namespaces, &out.Namespaces + *out = make([]TenantNamespace, len(*in)) + copy(*out, *in) + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TenantSpec. +func (in *TenantSpec) DeepCopy() *TenantSpec { + if in == nil { + return nil + } + out := new(TenantSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *TenantStatus) DeepCopyInto(out *TenantStatus) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TenantStatus. +func (in *TenantStatus) DeepCopy() *TenantStatus { + if in == nil { + return nil + } + out := new(TenantStatus) + in.DeepCopyInto(out) + return out +} diff --git a/poc/tenant-controller/pkg/clients/tenants/clientset/v1alpha1/clientset.go b/poc/tenant-controller/pkg/clients/tenants/clientset/v1alpha1/clientset.go new file mode 100644 index 000000000..4c98b0a6e --- /dev/null +++ b/poc/tenant-controller/pkg/clients/tenants/clientset/v1alpha1/clientset.go @@ -0,0 +1,85 @@ +// Copyright 2017 The Kubernetes Authors. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by client-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + discovery "k8s.io/client-go/discovery" + rest "k8s.io/client-go/rest" + flowcontrol "k8s.io/client-go/util/flowcontrol" + tenantsv1alpha1 "sigs.k8s.io/multi-tenancy/poc/tenant-controller/pkg/clients/tenants/clientset/v1alpha1/typed/tenants/v1alpha1" +) + +type Interface interface { + Discovery() discovery.DiscoveryInterface + TenantsV1alpha1() tenantsv1alpha1.TenantsV1alpha1Interface +} + +// Clientset contains the clients for groups. Each group has exactly one +// version included in a Clientset. +type Clientset struct { + *discovery.DiscoveryClient + tenantsV1alpha1 *tenantsv1alpha1.TenantsV1alpha1Client +} + +// TenantsV1alpha1 retrieves the TenantsV1alpha1Client +func (c *Clientset) TenantsV1alpha1() tenantsv1alpha1.TenantsV1alpha1Interface { + return c.tenantsV1alpha1 +} + +// Discovery retrieves the DiscoveryClient +func (c *Clientset) Discovery() discovery.DiscoveryInterface { + if c == nil { + return nil + } + return c.DiscoveryClient +} + +// NewForConfig creates a new Clientset for the given config. +func NewForConfig(c *rest.Config) (*Clientset, error) { + configShallowCopy := *c + if configShallowCopy.RateLimiter == nil && configShallowCopy.QPS > 0 { + configShallowCopy.RateLimiter = flowcontrol.NewTokenBucketRateLimiter(configShallowCopy.QPS, configShallowCopy.Burst) + } + var cs Clientset + var err error + cs.tenantsV1alpha1, err = tenantsv1alpha1.NewForConfig(&configShallowCopy) + if err != nil { + return nil, err + } + + cs.DiscoveryClient, err = discovery.NewDiscoveryClientForConfig(&configShallowCopy) + if err != nil { + return nil, err + } + return &cs, nil +} + +// NewForConfigOrDie creates a new Clientset for the given config and +// panics if there is an error in the config. +func NewForConfigOrDie(c *rest.Config) *Clientset { + var cs Clientset + cs.tenantsV1alpha1 = tenantsv1alpha1.NewForConfigOrDie(c) + + cs.DiscoveryClient = discovery.NewDiscoveryClientForConfigOrDie(c) + return &cs +} + +// New creates a new Clientset for the given RESTClient. +func New(c rest.Interface) *Clientset { + var cs Clientset + cs.tenantsV1alpha1 = tenantsv1alpha1.New(c) + + cs.DiscoveryClient = discovery.NewDiscoveryClient(c) + return &cs +} diff --git a/poc/tenant-controller/pkg/clients/tenants/clientset/v1alpha1/doc.go b/poc/tenant-controller/pkg/clients/tenants/clientset/v1alpha1/doc.go new file mode 100644 index 000000000..09e3191ef --- /dev/null +++ b/poc/tenant-controller/pkg/clients/tenants/clientset/v1alpha1/doc.go @@ -0,0 +1,15 @@ +// Copyright 2017 The Kubernetes Authors. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by client-gen. DO NOT EDIT. + +// This package has the automatically generated clientset. +package v1alpha1 diff --git a/poc/tenant-controller/pkg/clients/tenants/clientset/v1alpha1/fake/clientset_generated.go b/poc/tenant-controller/pkg/clients/tenants/clientset/v1alpha1/fake/clientset_generated.go new file mode 100644 index 000000000..1faa1f588 --- /dev/null +++ b/poc/tenant-controller/pkg/clients/tenants/clientset/v1alpha1/fake/clientset_generated.go @@ -0,0 +1,72 @@ +// Copyright 2017 The Kubernetes Authors. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by client-gen. DO NOT EDIT. + +package fake + +import ( + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/watch" + "k8s.io/client-go/discovery" + fakediscovery "k8s.io/client-go/discovery/fake" + "k8s.io/client-go/testing" + clientset "sigs.k8s.io/multi-tenancy/poc/tenant-controller/pkg/clients/tenants/clientset/v1alpha1" + tenantsv1alpha1 "sigs.k8s.io/multi-tenancy/poc/tenant-controller/pkg/clients/tenants/clientset/v1alpha1/typed/tenants/v1alpha1" + faketenantsv1alpha1 "sigs.k8s.io/multi-tenancy/poc/tenant-controller/pkg/clients/tenants/clientset/v1alpha1/typed/tenants/v1alpha1/fake" +) + +// NewSimpleClientset returns a clientset that will respond with the provided objects. +// It's backed by a very simple object tracker that processes creates, updates and deletions as-is, +// without applying any validations and/or defaults. It shouldn't be considered a replacement +// for a real clientset and is mostly useful in simple unit tests. +func NewSimpleClientset(objects ...runtime.Object) *Clientset { + o := testing.NewObjectTracker(scheme, codecs.UniversalDecoder()) + for _, obj := range objects { + if err := o.Add(obj); err != nil { + panic(err) + } + } + + cs := &Clientset{} + cs.discovery = &fakediscovery.FakeDiscovery{Fake: &cs.Fake} + cs.AddReactor("*", "*", testing.ObjectReaction(o)) + cs.AddWatchReactor("*", func(action testing.Action) (handled bool, ret watch.Interface, err error) { + gvr := action.GetResource() + ns := action.GetNamespace() + watch, err := o.Watch(gvr, ns) + if err != nil { + return false, nil, err + } + return true, watch, nil + }) + + return cs +} + +// Clientset implements clientset.Interface. Meant to be embedded into a +// struct to get a default implementation. This makes faking out just the method +// you want to test easier. +type Clientset struct { + testing.Fake + discovery *fakediscovery.FakeDiscovery +} + +func (c *Clientset) Discovery() discovery.DiscoveryInterface { + return c.discovery +} + +var _ clientset.Interface = &Clientset{} + +// TenantsV1alpha1 retrieves the TenantsV1alpha1Client +func (c *Clientset) TenantsV1alpha1() tenantsv1alpha1.TenantsV1alpha1Interface { + return &faketenantsv1alpha1.FakeTenantsV1alpha1{Fake: &c.Fake} +} diff --git a/poc/tenant-controller/pkg/clients/tenants/clientset/v1alpha1/fake/doc.go b/poc/tenant-controller/pkg/clients/tenants/clientset/v1alpha1/fake/doc.go new file mode 100644 index 000000000..93144e129 --- /dev/null +++ b/poc/tenant-controller/pkg/clients/tenants/clientset/v1alpha1/fake/doc.go @@ -0,0 +1,15 @@ +// Copyright 2017 The Kubernetes Authors. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by client-gen. DO NOT EDIT. + +// This package has the automatically generated fake clientset. +package fake diff --git a/poc/tenant-controller/pkg/clients/tenants/clientset/v1alpha1/fake/register.go b/poc/tenant-controller/pkg/clients/tenants/clientset/v1alpha1/fake/register.go new file mode 100644 index 000000000..9b271bd69 --- /dev/null +++ b/poc/tenant-controller/pkg/clients/tenants/clientset/v1alpha1/fake/register.go @@ -0,0 +1,51 @@ +// Copyright 2017 The Kubernetes Authors. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by client-gen. DO NOT EDIT. + +package fake + +import ( + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + schema "k8s.io/apimachinery/pkg/runtime/schema" + serializer "k8s.io/apimachinery/pkg/runtime/serializer" + utilruntime "k8s.io/apimachinery/pkg/util/runtime" + tenantsv1alpha1 "sigs.k8s.io/multi-tenancy/poc/tenant-controller/pkg/apis/tenants/v1alpha1" +) + +var scheme = runtime.NewScheme() +var codecs = serializer.NewCodecFactory(scheme) +var parameterCodec = runtime.NewParameterCodec(scheme) +var localSchemeBuilder = runtime.SchemeBuilder{ + tenantsv1alpha1.AddToScheme, +} + +// AddToScheme adds all types of this clientset into the given scheme. This allows composition +// of clientsets, like in: +// +// import ( +// "k8s.io/client-go/kubernetes" +// clientsetscheme "k8s.io/client-go/kubernetes/scheme" +// aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme" +// ) +// +// kclientset, _ := kubernetes.NewForConfig(c) +// _ = aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme) +// +// After this, RawExtensions in Kubernetes types will serialize kube-aggregator types +// correctly. +var AddToScheme = localSchemeBuilder.AddToScheme + +func init() { + v1.AddToGroupVersion(scheme, schema.GroupVersion{Version: "v1"}) + utilruntime.Must(AddToScheme(scheme)) +} diff --git a/poc/tenant-controller/pkg/clients/tenants/clientset/v1alpha1/scheme/doc.go b/poc/tenant-controller/pkg/clients/tenants/clientset/v1alpha1/scheme/doc.go new file mode 100644 index 000000000..b5279e668 --- /dev/null +++ b/poc/tenant-controller/pkg/clients/tenants/clientset/v1alpha1/scheme/doc.go @@ -0,0 +1,15 @@ +// Copyright 2017 The Kubernetes Authors. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by client-gen. DO NOT EDIT. + +// This package contains the scheme of the automatically generated clientset. +package scheme diff --git a/poc/tenant-controller/pkg/clients/tenants/clientset/v1alpha1/scheme/register.go b/poc/tenant-controller/pkg/clients/tenants/clientset/v1alpha1/scheme/register.go new file mode 100644 index 000000000..1c09054ee --- /dev/null +++ b/poc/tenant-controller/pkg/clients/tenants/clientset/v1alpha1/scheme/register.go @@ -0,0 +1,51 @@ +// Copyright 2017 The Kubernetes Authors. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by client-gen. DO NOT EDIT. + +package scheme + +import ( + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + schema "k8s.io/apimachinery/pkg/runtime/schema" + serializer "k8s.io/apimachinery/pkg/runtime/serializer" + utilruntime "k8s.io/apimachinery/pkg/util/runtime" + tenantsv1alpha1 "sigs.k8s.io/multi-tenancy/poc/tenant-controller/pkg/apis/tenants/v1alpha1" +) + +var Scheme = runtime.NewScheme() +var Codecs = serializer.NewCodecFactory(Scheme) +var ParameterCodec = runtime.NewParameterCodec(Scheme) +var localSchemeBuilder = runtime.SchemeBuilder{ + tenantsv1alpha1.AddToScheme, +} + +// AddToScheme adds all types of this clientset into the given scheme. This allows composition +// of clientsets, like in: +// +// import ( +// "k8s.io/client-go/kubernetes" +// clientsetscheme "k8s.io/client-go/kubernetes/scheme" +// aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme" +// ) +// +// kclientset, _ := kubernetes.NewForConfig(c) +// _ = aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme) +// +// After this, RawExtensions in Kubernetes types will serialize kube-aggregator types +// correctly. +var AddToScheme = localSchemeBuilder.AddToScheme + +func init() { + v1.AddToGroupVersion(Scheme, schema.GroupVersion{Version: "v1"}) + utilruntime.Must(AddToScheme(Scheme)) +} diff --git a/poc/tenant-controller/pkg/clients/tenants/clientset/v1alpha1/typed/tenants/v1alpha1/doc.go b/poc/tenant-controller/pkg/clients/tenants/clientset/v1alpha1/typed/tenants/v1alpha1/doc.go new file mode 100644 index 000000000..2c69f3f17 --- /dev/null +++ b/poc/tenant-controller/pkg/clients/tenants/clientset/v1alpha1/typed/tenants/v1alpha1/doc.go @@ -0,0 +1,15 @@ +// Copyright 2017 The Kubernetes Authors. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by client-gen. DO NOT EDIT. + +// This package has the automatically generated typed clients. +package v1alpha1 diff --git a/poc/tenant-controller/pkg/clients/tenants/clientset/v1alpha1/typed/tenants/v1alpha1/fake/doc.go b/poc/tenant-controller/pkg/clients/tenants/clientset/v1alpha1/typed/tenants/v1alpha1/fake/doc.go new file mode 100644 index 000000000..824e192fa --- /dev/null +++ b/poc/tenant-controller/pkg/clients/tenants/clientset/v1alpha1/typed/tenants/v1alpha1/fake/doc.go @@ -0,0 +1,15 @@ +// Copyright 2017 The Kubernetes Authors. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by client-gen. DO NOT EDIT. + +// Package fake has the automatically generated clients. +package fake diff --git a/poc/tenant-controller/pkg/clients/tenants/clientset/v1alpha1/typed/tenants/v1alpha1/fake/fake_tenant.go b/poc/tenant-controller/pkg/clients/tenants/clientset/v1alpha1/typed/tenants/v1alpha1/fake/fake_tenant.go new file mode 100644 index 000000000..2e3d54eb3 --- /dev/null +++ b/poc/tenant-controller/pkg/clients/tenants/clientset/v1alpha1/typed/tenants/v1alpha1/fake/fake_tenant.go @@ -0,0 +1,126 @@ +// Copyright 2017 The Kubernetes Authors. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by client-gen. DO NOT EDIT. + +package fake + +import ( + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + labels "k8s.io/apimachinery/pkg/labels" + schema "k8s.io/apimachinery/pkg/runtime/schema" + types "k8s.io/apimachinery/pkg/types" + watch "k8s.io/apimachinery/pkg/watch" + testing "k8s.io/client-go/testing" + v1alpha1 "sigs.k8s.io/multi-tenancy/poc/tenant-controller/pkg/apis/tenants/v1alpha1" +) + +// FakeTenants implements TenantInterface +type FakeTenants struct { + Fake *FakeTenantsV1alpha1 +} + +var tenantsResource = schema.GroupVersionResource{Group: "tenants.k8s.io", Version: "v1alpha1", Resource: "tenants"} + +var tenantsKind = schema.GroupVersionKind{Group: "tenants.k8s.io", Version: "v1alpha1", Kind: "Tenant"} + +// Get takes name of the tenant, and returns the corresponding tenant object, and an error if there is any. +func (c *FakeTenants) Get(name string, options v1.GetOptions) (result *v1alpha1.Tenant, err error) { + obj, err := c.Fake. + Invokes(testing.NewRootGetAction(tenantsResource, name), &v1alpha1.Tenant{}) + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.Tenant), err +} + +// List takes label and field selectors, and returns the list of Tenants that match those selectors. +func (c *FakeTenants) List(opts v1.ListOptions) (result *v1alpha1.TenantList, err error) { + obj, err := c.Fake. + Invokes(testing.NewRootListAction(tenantsResource, tenantsKind, opts), &v1alpha1.TenantList{}) + if obj == nil { + return nil, err + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &v1alpha1.TenantList{ListMeta: obj.(*v1alpha1.TenantList).ListMeta} + for _, item := range obj.(*v1alpha1.TenantList).Items { + if label.Matches(labels.Set(item.Labels)) { + list.Items = append(list.Items, item) + } + } + return list, err +} + +// Watch returns a watch.Interface that watches the requested tenants. +func (c *FakeTenants) Watch(opts v1.ListOptions) (watch.Interface, error) { + return c.Fake. + InvokesWatch(testing.NewRootWatchAction(tenantsResource, opts)) +} + +// Create takes the representation of a tenant and creates it. Returns the server's representation of the tenant, and an error, if there is any. +func (c *FakeTenants) Create(tenant *v1alpha1.Tenant) (result *v1alpha1.Tenant, err error) { + obj, err := c.Fake. + Invokes(testing.NewRootCreateAction(tenantsResource, tenant), &v1alpha1.Tenant{}) + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.Tenant), err +} + +// Update takes the representation of a tenant and updates it. Returns the server's representation of the tenant, and an error, if there is any. +func (c *FakeTenants) Update(tenant *v1alpha1.Tenant) (result *v1alpha1.Tenant, err error) { + obj, err := c.Fake. + Invokes(testing.NewRootUpdateAction(tenantsResource, tenant), &v1alpha1.Tenant{}) + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.Tenant), err +} + +// UpdateStatus was generated because the type contains a Status member. +// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). +func (c *FakeTenants) UpdateStatus(tenant *v1alpha1.Tenant) (*v1alpha1.Tenant, error) { + obj, err := c.Fake. + Invokes(testing.NewRootUpdateSubresourceAction(tenantsResource, "status", tenant), &v1alpha1.Tenant{}) + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.Tenant), err +} + +// Delete takes name of the tenant and deletes it. Returns an error if one occurs. +func (c *FakeTenants) Delete(name string, options *v1.DeleteOptions) error { + _, err := c.Fake. + Invokes(testing.NewRootDeleteAction(tenantsResource, name), &v1alpha1.Tenant{}) + return err +} + +// DeleteCollection deletes a collection of objects. +func (c *FakeTenants) DeleteCollection(options *v1.DeleteOptions, listOptions v1.ListOptions) error { + action := testing.NewRootDeleteCollectionAction(tenantsResource, listOptions) + + _, err := c.Fake.Invokes(action, &v1alpha1.TenantList{}) + return err +} + +// Patch applies the patch and returns the patched tenant. +func (c *FakeTenants) Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1alpha1.Tenant, err error) { + obj, err := c.Fake. + Invokes(testing.NewRootPatchSubresourceAction(tenantsResource, name, pt, data, subresources...), &v1alpha1.Tenant{}) + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.Tenant), err +} diff --git a/poc/tenant-controller/pkg/clients/tenants/clientset/v1alpha1/typed/tenants/v1alpha1/fake/fake_tenants_client.go b/poc/tenant-controller/pkg/clients/tenants/clientset/v1alpha1/typed/tenants/v1alpha1/fake/fake_tenants_client.go new file mode 100644 index 000000000..7362bcd22 --- /dev/null +++ b/poc/tenant-controller/pkg/clients/tenants/clientset/v1alpha1/typed/tenants/v1alpha1/fake/fake_tenants_client.go @@ -0,0 +1,35 @@ +// Copyright 2017 The Kubernetes Authors. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by client-gen. DO NOT EDIT. + +package fake + +import ( + rest "k8s.io/client-go/rest" + testing "k8s.io/client-go/testing" + v1alpha1 "sigs.k8s.io/multi-tenancy/poc/tenant-controller/pkg/clients/tenants/clientset/v1alpha1/typed/tenants/v1alpha1" +) + +type FakeTenantsV1alpha1 struct { + *testing.Fake +} + +func (c *FakeTenantsV1alpha1) Tenants() v1alpha1.TenantInterface { + return &FakeTenants{c} +} + +// RESTClient returns a RESTClient that is used to communicate +// with API server by this client implementation. +func (c *FakeTenantsV1alpha1) RESTClient() rest.Interface { + var ret *rest.RESTClient + return ret +} diff --git a/poc/tenant-controller/pkg/clients/tenants/clientset/v1alpha1/typed/tenants/v1alpha1/generated_expansion.go b/poc/tenant-controller/pkg/clients/tenants/clientset/v1alpha1/typed/tenants/v1alpha1/generated_expansion.go new file mode 100644 index 000000000..4c08d3dd0 --- /dev/null +++ b/poc/tenant-controller/pkg/clients/tenants/clientset/v1alpha1/typed/tenants/v1alpha1/generated_expansion.go @@ -0,0 +1,16 @@ +// Copyright 2017 The Kubernetes Authors. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by client-gen. DO NOT EDIT. + +package v1alpha1 + +type TenantExpansion interface{} diff --git a/poc/tenant-controller/pkg/clients/tenants/clientset/v1alpha1/typed/tenants/v1alpha1/tenant.go b/poc/tenant-controller/pkg/clients/tenants/clientset/v1alpha1/typed/tenants/v1alpha1/tenant.go new file mode 100644 index 000000000..e67302b03 --- /dev/null +++ b/poc/tenant-controller/pkg/clients/tenants/clientset/v1alpha1/typed/tenants/v1alpha1/tenant.go @@ -0,0 +1,175 @@ +// Copyright 2017 The Kubernetes Authors. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by client-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + "time" + + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + types "k8s.io/apimachinery/pkg/types" + watch "k8s.io/apimachinery/pkg/watch" + rest "k8s.io/client-go/rest" + v1alpha1 "sigs.k8s.io/multi-tenancy/poc/tenant-controller/pkg/apis/tenants/v1alpha1" + scheme "sigs.k8s.io/multi-tenancy/poc/tenant-controller/pkg/clients/tenants/clientset/v1alpha1/scheme" +) + +// TenantsGetter has a method to return a TenantInterface. +// A group's client should implement this interface. +type TenantsGetter interface { + Tenants() TenantInterface +} + +// TenantInterface has methods to work with Tenant resources. +type TenantInterface interface { + Create(*v1alpha1.Tenant) (*v1alpha1.Tenant, error) + Update(*v1alpha1.Tenant) (*v1alpha1.Tenant, error) + UpdateStatus(*v1alpha1.Tenant) (*v1alpha1.Tenant, error) + Delete(name string, options *v1.DeleteOptions) error + DeleteCollection(options *v1.DeleteOptions, listOptions v1.ListOptions) error + Get(name string, options v1.GetOptions) (*v1alpha1.Tenant, error) + List(opts v1.ListOptions) (*v1alpha1.TenantList, error) + Watch(opts v1.ListOptions) (watch.Interface, error) + Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1alpha1.Tenant, err error) + TenantExpansion +} + +// tenants implements TenantInterface +type tenants struct { + client rest.Interface +} + +// newTenants returns a Tenants +func newTenants(c *TenantsV1alpha1Client) *tenants { + return &tenants{ + client: c.RESTClient(), + } +} + +// Get takes name of the tenant, and returns the corresponding tenant object, and an error if there is any. +func (c *tenants) Get(name string, options v1.GetOptions) (result *v1alpha1.Tenant, err error) { + result = &v1alpha1.Tenant{} + err = c.client.Get(). + Resource("tenants"). + Name(name). + VersionedParams(&options, scheme.ParameterCodec). + Do(). + Into(result) + return +} + +// List takes label and field selectors, and returns the list of Tenants that match those selectors. +func (c *tenants) List(opts v1.ListOptions) (result *v1alpha1.TenantList, err error) { + var timeout time.Duration + if opts.TimeoutSeconds != nil { + timeout = time.Duration(*opts.TimeoutSeconds) * time.Second + } + result = &v1alpha1.TenantList{} + err = c.client.Get(). + Resource("tenants"). + VersionedParams(&opts, scheme.ParameterCodec). + Timeout(timeout). + Do(). + Into(result) + return +} + +// Watch returns a watch.Interface that watches the requested tenants. +func (c *tenants) Watch(opts v1.ListOptions) (watch.Interface, error) { + var timeout time.Duration + if opts.TimeoutSeconds != nil { + timeout = time.Duration(*opts.TimeoutSeconds) * time.Second + } + opts.Watch = true + return c.client.Get(). + Resource("tenants"). + VersionedParams(&opts, scheme.ParameterCodec). + Timeout(timeout). + Watch() +} + +// Create takes the representation of a tenant and creates it. Returns the server's representation of the tenant, and an error, if there is any. +func (c *tenants) Create(tenant *v1alpha1.Tenant) (result *v1alpha1.Tenant, err error) { + result = &v1alpha1.Tenant{} + err = c.client.Post(). + Resource("tenants"). + Body(tenant). + Do(). + Into(result) + return +} + +// Update takes the representation of a tenant and updates it. Returns the server's representation of the tenant, and an error, if there is any. +func (c *tenants) Update(tenant *v1alpha1.Tenant) (result *v1alpha1.Tenant, err error) { + result = &v1alpha1.Tenant{} + err = c.client.Put(). + Resource("tenants"). + Name(tenant.Name). + Body(tenant). + Do(). + Into(result) + return +} + +// UpdateStatus was generated because the type contains a Status member. +// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). + +func (c *tenants) UpdateStatus(tenant *v1alpha1.Tenant) (result *v1alpha1.Tenant, err error) { + result = &v1alpha1.Tenant{} + err = c.client.Put(). + Resource("tenants"). + Name(tenant.Name). + SubResource("status"). + Body(tenant). + Do(). + Into(result) + return +} + +// Delete takes name of the tenant and deletes it. Returns an error if one occurs. +func (c *tenants) Delete(name string, options *v1.DeleteOptions) error { + return c.client.Delete(). + Resource("tenants"). + Name(name). + Body(options). + Do(). + Error() +} + +// DeleteCollection deletes a collection of objects. +func (c *tenants) DeleteCollection(options *v1.DeleteOptions, listOptions v1.ListOptions) error { + var timeout time.Duration + if listOptions.TimeoutSeconds != nil { + timeout = time.Duration(*listOptions.TimeoutSeconds) * time.Second + } + return c.client.Delete(). + Resource("tenants"). + VersionedParams(&listOptions, scheme.ParameterCodec). + Timeout(timeout). + Body(options). + Do(). + Error() +} + +// Patch applies the patch and returns the patched tenant. +func (c *tenants) Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1alpha1.Tenant, err error) { + result = &v1alpha1.Tenant{} + err = c.client.Patch(pt). + Resource("tenants"). + SubResource(subresources...). + Name(name). + Body(data). + Do(). + Into(result) + return +} diff --git a/poc/tenant-controller/pkg/clients/tenants/clientset/v1alpha1/typed/tenants/v1alpha1/tenants_client.go b/poc/tenant-controller/pkg/clients/tenants/clientset/v1alpha1/typed/tenants/v1alpha1/tenants_client.go new file mode 100644 index 000000000..8f8e04a33 --- /dev/null +++ b/poc/tenant-controller/pkg/clients/tenants/clientset/v1alpha1/typed/tenants/v1alpha1/tenants_client.go @@ -0,0 +1,85 @@ +// Copyright 2017 The Kubernetes Authors. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by client-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + serializer "k8s.io/apimachinery/pkg/runtime/serializer" + rest "k8s.io/client-go/rest" + v1alpha1 "sigs.k8s.io/multi-tenancy/poc/tenant-controller/pkg/apis/tenants/v1alpha1" + "sigs.k8s.io/multi-tenancy/poc/tenant-controller/pkg/clients/tenants/clientset/v1alpha1/scheme" +) + +type TenantsV1alpha1Interface interface { + RESTClient() rest.Interface + TenantsGetter +} + +// TenantsV1alpha1Client is used to interact with features provided by the tenants.k8s.io group. +type TenantsV1alpha1Client struct { + restClient rest.Interface +} + +func (c *TenantsV1alpha1Client) Tenants() TenantInterface { + return newTenants(c) +} + +// NewForConfig creates a new TenantsV1alpha1Client for the given config. +func NewForConfig(c *rest.Config) (*TenantsV1alpha1Client, error) { + config := *c + if err := setConfigDefaults(&config); err != nil { + return nil, err + } + client, err := rest.RESTClientFor(&config) + if err != nil { + return nil, err + } + return &TenantsV1alpha1Client{client}, nil +} + +// NewForConfigOrDie creates a new TenantsV1alpha1Client for the given config and +// panics if there is an error in the config. +func NewForConfigOrDie(c *rest.Config) *TenantsV1alpha1Client { + client, err := NewForConfig(c) + if err != nil { + panic(err) + } + return client +} + +// New creates a new TenantsV1alpha1Client for the given RESTClient. +func New(c rest.Interface) *TenantsV1alpha1Client { + return &TenantsV1alpha1Client{c} +} + +func setConfigDefaults(config *rest.Config) error { + gv := v1alpha1.SchemeGroupVersion + config.GroupVersion = &gv + config.APIPath = "/apis" + config.NegotiatedSerializer = serializer.DirectCodecFactory{CodecFactory: scheme.Codecs} + + if config.UserAgent == "" { + config.UserAgent = rest.DefaultKubernetesUserAgent() + } + + return nil +} + +// RESTClient returns a RESTClient that is used to communicate +// with API server by this client implementation. +func (c *TenantsV1alpha1Client) RESTClient() rest.Interface { + if c == nil { + return nil + } + return c.restClient +} diff --git a/poc/tenant-controller/pkg/clients/tenants/informers/externalversions/factory.go b/poc/tenant-controller/pkg/clients/tenants/informers/externalversions/factory.go new file mode 100644 index 000000000..8ac8af410 --- /dev/null +++ b/poc/tenant-controller/pkg/clients/tenants/informers/externalversions/factory.go @@ -0,0 +1,175 @@ +// Copyright 2017 The Kubernetes Authors. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by informer-gen. DO NOT EDIT. + +package externalversions + +import ( + reflect "reflect" + sync "sync" + time "time" + + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + schema "k8s.io/apimachinery/pkg/runtime/schema" + cache "k8s.io/client-go/tools/cache" + v1alpha1 "sigs.k8s.io/multi-tenancy/poc/tenant-controller/pkg/clients/tenants/clientset/v1alpha1" + internalinterfaces "sigs.k8s.io/multi-tenancy/poc/tenant-controller/pkg/clients/tenants/informers/externalversions/internalinterfaces" + tenants "sigs.k8s.io/multi-tenancy/poc/tenant-controller/pkg/clients/tenants/informers/externalversions/tenants" +) + +// SharedInformerOption defines the functional option type for SharedInformerFactory. +type SharedInformerOption func(*sharedInformerFactory) *sharedInformerFactory + +type sharedInformerFactory struct { + client v1alpha1.Interface + namespace string + tweakListOptions internalinterfaces.TweakListOptionsFunc + lock sync.Mutex + defaultResync time.Duration + customResync map[reflect.Type]time.Duration + + informers map[reflect.Type]cache.SharedIndexInformer + // startedInformers is used for tracking which informers have been started. + // This allows Start() to be called multiple times safely. + startedInformers map[reflect.Type]bool +} + +// WithCustomResyncConfig sets a custom resync period for the specified informer types. +func WithCustomResyncConfig(resyncConfig map[v1.Object]time.Duration) SharedInformerOption { + return func(factory *sharedInformerFactory) *sharedInformerFactory { + for k, v := range resyncConfig { + factory.customResync[reflect.TypeOf(k)] = v + } + return factory + } +} + +// WithTweakListOptions sets a custom filter on all listers of the configured SharedInformerFactory. +func WithTweakListOptions(tweakListOptions internalinterfaces.TweakListOptionsFunc) SharedInformerOption { + return func(factory *sharedInformerFactory) *sharedInformerFactory { + factory.tweakListOptions = tweakListOptions + return factory + } +} + +// WithNamespace limits the SharedInformerFactory to the specified namespace. +func WithNamespace(namespace string) SharedInformerOption { + return func(factory *sharedInformerFactory) *sharedInformerFactory { + factory.namespace = namespace + return factory + } +} + +// NewSharedInformerFactory constructs a new instance of sharedInformerFactory for all namespaces. +func NewSharedInformerFactory(client v1alpha1.Interface, defaultResync time.Duration) SharedInformerFactory { + return NewSharedInformerFactoryWithOptions(client, defaultResync) +} + +// NewFilteredSharedInformerFactory constructs a new instance of sharedInformerFactory. +// Listers obtained via this SharedInformerFactory will be subject to the same filters +// as specified here. +// Deprecated: Please use NewSharedInformerFactoryWithOptions instead +func NewFilteredSharedInformerFactory(client v1alpha1.Interface, defaultResync time.Duration, namespace string, tweakListOptions internalinterfaces.TweakListOptionsFunc) SharedInformerFactory { + return NewSharedInformerFactoryWithOptions(client, defaultResync, WithNamespace(namespace), WithTweakListOptions(tweakListOptions)) +} + +// NewSharedInformerFactoryWithOptions constructs a new instance of a SharedInformerFactory with additional options. +func NewSharedInformerFactoryWithOptions(client v1alpha1.Interface, defaultResync time.Duration, options ...SharedInformerOption) SharedInformerFactory { + factory := &sharedInformerFactory{ + client: client, + namespace: v1.NamespaceAll, + defaultResync: defaultResync, + informers: make(map[reflect.Type]cache.SharedIndexInformer), + startedInformers: make(map[reflect.Type]bool), + customResync: make(map[reflect.Type]time.Duration), + } + + // Apply all options + for _, opt := range options { + factory = opt(factory) + } + + return factory +} + +// Start initializes all requested informers. +func (f *sharedInformerFactory) Start(stopCh <-chan struct{}) { + f.lock.Lock() + defer f.lock.Unlock() + + for informerType, informer := range f.informers { + if !f.startedInformers[informerType] { + go informer.Run(stopCh) + f.startedInformers[informerType] = true + } + } +} + +// WaitForCacheSync waits for all started informers' cache were synced. +func (f *sharedInformerFactory) WaitForCacheSync(stopCh <-chan struct{}) map[reflect.Type]bool { + informers := func() map[reflect.Type]cache.SharedIndexInformer { + f.lock.Lock() + defer f.lock.Unlock() + + informers := map[reflect.Type]cache.SharedIndexInformer{} + for informerType, informer := range f.informers { + if f.startedInformers[informerType] { + informers[informerType] = informer + } + } + return informers + }() + + res := map[reflect.Type]bool{} + for informType, informer := range informers { + res[informType] = cache.WaitForCacheSync(stopCh, informer.HasSynced) + } + return res +} + +// InternalInformerFor returns the SharedIndexInformer for obj using an internal +// client. +func (f *sharedInformerFactory) InformerFor(obj runtime.Object, newFunc internalinterfaces.NewInformerFunc) cache.SharedIndexInformer { + f.lock.Lock() + defer f.lock.Unlock() + + informerType := reflect.TypeOf(obj) + informer, exists := f.informers[informerType] + if exists { + return informer + } + + resyncPeriod, exists := f.customResync[informerType] + if !exists { + resyncPeriod = f.defaultResync + } + + informer = newFunc(f.client, resyncPeriod) + f.informers[informerType] = informer + + return informer +} + +// SharedInformerFactory provides shared informers for resources in all known +// API group versions. +type SharedInformerFactory interface { + internalinterfaces.SharedInformerFactory + ForResource(resource schema.GroupVersionResource) (GenericInformer, error) + WaitForCacheSync(stopCh <-chan struct{}) map[reflect.Type]bool + + Tenants() tenants.Interface +} + +func (f *sharedInformerFactory) Tenants() tenants.Interface { + return tenants.New(f, f.namespace, f.tweakListOptions) +} diff --git a/poc/tenant-controller/pkg/clients/tenants/informers/externalversions/generic.go b/poc/tenant-controller/pkg/clients/tenants/informers/externalversions/generic.go new file mode 100644 index 000000000..8ddac5295 --- /dev/null +++ b/poc/tenant-controller/pkg/clients/tenants/informers/externalversions/generic.go @@ -0,0 +1,57 @@ +// Copyright 2017 The Kubernetes Authors. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by informer-gen. DO NOT EDIT. + +package externalversions + +import ( + "fmt" + + schema "k8s.io/apimachinery/pkg/runtime/schema" + cache "k8s.io/client-go/tools/cache" + v1alpha1 "sigs.k8s.io/multi-tenancy/poc/tenant-controller/pkg/apis/tenants/v1alpha1" +) + +// GenericInformer is type of SharedIndexInformer which will locate and delegate to other +// sharedInformers based on type +type GenericInformer interface { + Informer() cache.SharedIndexInformer + Lister() cache.GenericLister +} + +type genericInformer struct { + informer cache.SharedIndexInformer + resource schema.GroupResource +} + +// Informer returns the SharedIndexInformer. +func (f *genericInformer) Informer() cache.SharedIndexInformer { + return f.informer +} + +// Lister returns the GenericLister. +func (f *genericInformer) Lister() cache.GenericLister { + return cache.NewGenericLister(f.Informer().GetIndexer(), f.resource) +} + +// ForResource gives generic access to a shared informer of the matching type +// TODO extend this to unknown resources with a client pool +func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource) (GenericInformer, error) { + switch resource { + // Group=tenants.k8s.io, Version=v1alpha1 + case v1alpha1.SchemeGroupVersion.WithResource("tenants"): + return &genericInformer{resource: resource.GroupResource(), informer: f.Tenants().V1alpha1().Tenants().Informer()}, nil + + } + + return nil, fmt.Errorf("no informer found for %v", resource) +} diff --git a/poc/tenant-controller/pkg/clients/tenants/informers/externalversions/internalinterfaces/factory_interfaces.go b/poc/tenant-controller/pkg/clients/tenants/informers/externalversions/internalinterfaces/factory_interfaces.go new file mode 100644 index 000000000..38735512f --- /dev/null +++ b/poc/tenant-controller/pkg/clients/tenants/informers/externalversions/internalinterfaces/factory_interfaces.go @@ -0,0 +1,35 @@ +// Copyright 2017 The Kubernetes Authors. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by informer-gen. DO NOT EDIT. + +package internalinterfaces + +import ( + time "time" + + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + cache "k8s.io/client-go/tools/cache" + v1alpha1 "sigs.k8s.io/multi-tenancy/poc/tenant-controller/pkg/clients/tenants/clientset/v1alpha1" +) + +// NewInformerFunc takes v1alpha1.Interface and time.Duration to return a SharedIndexInformer. +type NewInformerFunc func(v1alpha1.Interface, time.Duration) cache.SharedIndexInformer + +// SharedInformerFactory a small interface to allow for adding an informer without an import cycle +type SharedInformerFactory interface { + Start(stopCh <-chan struct{}) + InformerFor(obj runtime.Object, newFunc NewInformerFunc) cache.SharedIndexInformer +} + +// TweakListOptionsFunc is a function that transforms a v1.ListOptions. +type TweakListOptionsFunc func(*v1.ListOptions) diff --git a/poc/tenant-controller/pkg/clients/tenants/informers/externalversions/tenants/interface.go b/poc/tenant-controller/pkg/clients/tenants/informers/externalversions/tenants/interface.go new file mode 100644 index 000000000..03712924f --- /dev/null +++ b/poc/tenant-controller/pkg/clients/tenants/informers/externalversions/tenants/interface.go @@ -0,0 +1,41 @@ +// Copyright 2017 The Kubernetes Authors. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by informer-gen. DO NOT EDIT. + +package tenants + +import ( + internalinterfaces "sigs.k8s.io/multi-tenancy/poc/tenant-controller/pkg/clients/tenants/informers/externalversions/internalinterfaces" + v1alpha1 "sigs.k8s.io/multi-tenancy/poc/tenant-controller/pkg/clients/tenants/informers/externalversions/tenants/v1alpha1" +) + +// Interface provides access to each of this group's versions. +type Interface interface { + // V1alpha1 provides access to shared informers for resources in V1alpha1. + V1alpha1() v1alpha1.Interface +} + +type group struct { + factory internalinterfaces.SharedInformerFactory + namespace string + tweakListOptions internalinterfaces.TweakListOptionsFunc +} + +// New returns a new Interface. +func New(f internalinterfaces.SharedInformerFactory, namespace string, tweakListOptions internalinterfaces.TweakListOptionsFunc) Interface { + return &group{factory: f, namespace: namespace, tweakListOptions: tweakListOptions} +} + +// V1alpha1 returns a new v1alpha1.Interface. +func (g *group) V1alpha1() v1alpha1.Interface { + return v1alpha1.New(g.factory, g.namespace, g.tweakListOptions) +} diff --git a/poc/tenant-controller/pkg/clients/tenants/informers/externalversions/tenants/v1alpha1/interface.go b/poc/tenant-controller/pkg/clients/tenants/informers/externalversions/tenants/v1alpha1/interface.go new file mode 100644 index 000000000..bc347f5b7 --- /dev/null +++ b/poc/tenant-controller/pkg/clients/tenants/informers/externalversions/tenants/v1alpha1/interface.go @@ -0,0 +1,40 @@ +// Copyright 2017 The Kubernetes Authors. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by informer-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + internalinterfaces "sigs.k8s.io/multi-tenancy/poc/tenant-controller/pkg/clients/tenants/informers/externalversions/internalinterfaces" +) + +// Interface provides access to all the informers in this group version. +type Interface interface { + // Tenants returns a TenantInformer. + Tenants() TenantInformer +} + +type version struct { + factory internalinterfaces.SharedInformerFactory + namespace string + tweakListOptions internalinterfaces.TweakListOptionsFunc +} + +// New returns a new Interface. +func New(f internalinterfaces.SharedInformerFactory, namespace string, tweakListOptions internalinterfaces.TweakListOptionsFunc) Interface { + return &version{factory: f, namespace: namespace, tweakListOptions: tweakListOptions} +} + +// Tenants returns a TenantInformer. +func (v *version) Tenants() TenantInformer { + return &tenantInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} +} diff --git a/poc/tenant-controller/pkg/clients/tenants/informers/externalversions/tenants/v1alpha1/tenant.go b/poc/tenant-controller/pkg/clients/tenants/informers/externalversions/tenants/v1alpha1/tenant.go new file mode 100644 index 000000000..6d06cc210 --- /dev/null +++ b/poc/tenant-controller/pkg/clients/tenants/informers/externalversions/tenants/v1alpha1/tenant.go @@ -0,0 +1,83 @@ +// Copyright 2017 The Kubernetes Authors. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by informer-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + time "time" + + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + watch "k8s.io/apimachinery/pkg/watch" + cache "k8s.io/client-go/tools/cache" + tenantsv1alpha1 "sigs.k8s.io/multi-tenancy/poc/tenant-controller/pkg/apis/tenants/v1alpha1" + clientsetv1alpha1 "sigs.k8s.io/multi-tenancy/poc/tenant-controller/pkg/clients/tenants/clientset/v1alpha1" + internalinterfaces "sigs.k8s.io/multi-tenancy/poc/tenant-controller/pkg/clients/tenants/informers/externalversions/internalinterfaces" + v1alpha1 "sigs.k8s.io/multi-tenancy/poc/tenant-controller/pkg/clients/tenants/listers/tenants/v1alpha1" +) + +// TenantInformer provides access to a shared informer and lister for +// Tenants. +type TenantInformer interface { + Informer() cache.SharedIndexInformer + Lister() v1alpha1.TenantLister +} + +type tenantInformer struct { + factory internalinterfaces.SharedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc +} + +// NewTenantInformer constructs a new informer for Tenant type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory footprint and number of connections to the server. +func NewTenantInformer(client clientsetv1alpha1.Interface, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return NewFilteredTenantInformer(client, resyncPeriod, indexers, nil) +} + +// NewFilteredTenantInformer constructs a new informer for Tenant type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory footprint and number of connections to the server. +func NewFilteredTenantInformer(client clientsetv1alpha1.Interface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { + return cache.NewSharedIndexInformer( + &cache.ListWatch{ + ListFunc: func(options v1.ListOptions) (runtime.Object, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.TenantsV1alpha1().Tenants().List(options) + }, + WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.TenantsV1alpha1().Tenants().Watch(options) + }, + }, + &tenantsv1alpha1.Tenant{}, + resyncPeriod, + indexers, + ) +} + +func (f *tenantInformer) defaultInformer(client clientsetv1alpha1.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewFilteredTenantInformer(client, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) +} + +func (f *tenantInformer) Informer() cache.SharedIndexInformer { + return f.factory.InformerFor(&tenantsv1alpha1.Tenant{}, f.defaultInformer) +} + +func (f *tenantInformer) Lister() v1alpha1.TenantLister { + return v1alpha1.NewTenantLister(f.Informer().GetIndexer()) +} diff --git a/poc/tenant-controller/pkg/clients/tenants/listers/tenants/v1alpha1/expansion_generated.go b/poc/tenant-controller/pkg/clients/tenants/listers/tenants/v1alpha1/expansion_generated.go new file mode 100644 index 000000000..6d6ab2102 --- /dev/null +++ b/poc/tenant-controller/pkg/clients/tenants/listers/tenants/v1alpha1/expansion_generated.go @@ -0,0 +1,18 @@ +// Copyright 2017 The Kubernetes Authors. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by lister-gen. DO NOT EDIT. + +package v1alpha1 + +// TenantListerExpansion allows custom methods to be added to +// TenantLister. +type TenantListerExpansion interface{} diff --git a/poc/tenant-controller/pkg/clients/tenants/listers/tenants/v1alpha1/tenant.go b/poc/tenant-controller/pkg/clients/tenants/listers/tenants/v1alpha1/tenant.go new file mode 100644 index 000000000..a891aa373 --- /dev/null +++ b/poc/tenant-controller/pkg/clients/tenants/listers/tenants/v1alpha1/tenant.go @@ -0,0 +1,60 @@ +// Copyright 2017 The Kubernetes Authors. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by lister-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + "k8s.io/apimachinery/pkg/api/errors" + "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/tools/cache" + v1alpha1 "sigs.k8s.io/multi-tenancy/poc/tenant-controller/pkg/apis/tenants/v1alpha1" +) + +// TenantLister helps list Tenants. +type TenantLister interface { + // List lists all Tenants in the indexer. + List(selector labels.Selector) (ret []*v1alpha1.Tenant, err error) + // Get retrieves the Tenant from the index for a given name. + Get(name string) (*v1alpha1.Tenant, error) + TenantListerExpansion +} + +// tenantLister implements the TenantLister interface. +type tenantLister struct { + indexer cache.Indexer +} + +// NewTenantLister returns a new TenantLister. +func NewTenantLister(indexer cache.Indexer) TenantLister { + return &tenantLister{indexer: indexer} +} + +// List lists all Tenants in the indexer. +func (s *tenantLister) List(selector labels.Selector) (ret []*v1alpha1.Tenant, err error) { + err = cache.ListAll(s.indexer, selector, func(m interface{}) { + ret = append(ret, m.(*v1alpha1.Tenant)) + }) + return ret, err +} + +// Get retrieves the Tenant from the index for a given name. +func (s *tenantLister) Get(name string) (*v1alpha1.Tenant, error) { + obj, exists, err := s.indexer.GetByKey(name) + if err != nil { + return nil, err + } + if !exists { + return nil, errors.NewNotFound(v1alpha1.Resource("tenant"), name) + } + return obj.(*v1alpha1.Tenant), nil +} diff --git a/poc/tenant-controller/pkg/controllers/tenants/controller.go b/poc/tenant-controller/pkg/controllers/tenants/controller.go new file mode 100644 index 000000000..fcf6e26d4 --- /dev/null +++ b/poc/tenant-controller/pkg/controllers/tenants/controller.go @@ -0,0 +1,73 @@ +// Copyright 2017 The Kubernetes Authors. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package tenants + +import ( + "context" + "fmt" + + "github.com/golang/glog" + apirt "k8s.io/apimachinery/pkg/util/runtime" + "k8s.io/client-go/tools/cache" + tenantsapi "sigs.k8s.io/multi-tenancy/poc/tenant-controller/pkg/apis/tenants/v1alpha1" + tenantsclient "sigs.k8s.io/multi-tenancy/poc/tenant-controller/pkg/clients/tenants/clientset/v1alpha1" + tenantsinformers "sigs.k8s.io/multi-tenancy/poc/tenant-controller/pkg/clients/tenants/informers/externalversions" +) + +// Controller is k8s controller managing Tenant CRDs. +type Controller struct { + informer cache.SharedIndexInformer +} + +// NewController creates the controller. +func NewController(client tenantsclient.Interface, informerFactory tenantsinformers.SharedInformerFactory) *Controller { + c := &Controller{ + informer: informerFactory.Tenants().V1alpha1().Tenants().Informer(), + } + c.informer.AddEventHandler(cache.ResourceEventHandlerFuncs{ + AddFunc: func(o interface{}) { c.createTenant(o.(*tenantsapi.Tenant)) }, + UpdateFunc: func(o, n interface{}) { c.updateTenant(o.(*tenantsapi.Tenant), n.(*tenantsapi.Tenant)) }, + DeleteFunc: func(o interface{}) { c.deleteTenant(o.(*tenantsapi.Tenant)) }, + }) + return c +} + +// Run implements the controller logic. +func (c *Controller) Run(ctx context.Context) error { + defer apirt.HandleCrash() + + glog.Info("waiting for cache sync") + if !cache.WaitForCacheSync(ctx.Done(), c.informer.HasSynced) { + return fmt.Errorf("cache sync failed") + } + + glog.Info("controller started") + <-ctx.Done() + glog.Info("controller stopped") + + return nil +} + +func (c *Controller) createTenant(obj *tenantsapi.Tenant) { + // TODO + glog.Info("createTenant: %#v", obj) +} + +func (c *Controller) updateTenant(old, obj *tenantsapi.Tenant) { + // TODO + glog.Info("updateTenant: %#v", obj) +} + +func (c *Controller) deleteTenant(obj *tenantsapi.Tenant) { + // TODO + glog.Info("deleteTenant: %#v", obj) +} diff --git a/tools/bin/devtk b/tools/bin/devtk new file mode 100755 index 000000000..bb5c294fa --- /dev/null +++ b/tools/bin/devtk @@ -0,0 +1,20 @@ +#!/bin/bash +# +# Copyright 2018 The Kubernetes Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +export REPO_ROOT="$(cd $(dirname ${BASH_SOURCE[0]})/../..; pwd)" +. $REPO_ROOT/tools/lib/functions.sh +cmdlet_run devtk "$@" + diff --git a/tools/lib/devtk/cmd-build.sh b/tools/lib/devtk/cmd-build.sh new file mode 100644 index 000000000..2c0f5a8b4 --- /dev/null +++ b/tools/lib/devtk/cmd-build.sh @@ -0,0 +1,63 @@ +# Copyright 2018 The Kubernetes Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Usage: +# devtk build # build all binaries from all poc projects +# devtk build tenant-ctl # example, build specified binary +# +# # if tenant-ctl is ambiguous across multiple projects, +# # specify project explicitly, e.g. +# devtk build tenant-controller/tenant-ctl + +function build_cmd() { + local project="$1" cmd="$2" + echo "build $project/$cmd" + mkdir -p $REPO_ROOT/out/$project + ( + cd poc/$project + go build -o $REPO_ROOT/out/$project/$cmd ./cmd/$cmd + ) +} + +function find_pkg_and_build() { + # the argument is "cmd" or "project/cmd" + local cmd="$(basename $1)" project="$(dirname $1)" + if [ -z "$project" -o "$project" == "." ]; then + project="" + for d in $(find poc -mindepth 1 -maxdepth 1 -type d); do + test -d $d/cmd/$cmd/main.go || continue + local p="${d##poc/}" + test -z "$project" || fatal "ambiguous name $cmd: $project/$cmd or $p/$cmd" + project="$p" + done + test -n "$project" || fatal "known name $cmd, please use format of PROJECT/CMD" + build_cmd "$project" "$cmd" + fi +} + +function cmd_run() { + cd $REPO_ROOT + if [ $# -gt 0 ]; then + for arg; do + find_pkg_and_build "$arg" + done + else + for fn in poc/*/cmd/*/main.go; do + local dir="$(dirname ${fn##poc/})" + local project="${dir%%/cmd/*}" + local cmd="${dir##*/}" + build_cmd "$project" "$cmd" + done + fi +} diff --git a/tools/lib/devtk/cmd-codegen.sh b/tools/lib/devtk/cmd-codegen.sh new file mode 100644 index 000000000..bdb66e111 --- /dev/null +++ b/tools/lib/devtk/cmd-codegen.sh @@ -0,0 +1,59 @@ +# Copyright 2018 The Kubernetes Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Usage: +# devtk codegen # generate code for all poc projects +# devtk codegen proj1 proj2 # generate code for specified poc projects +# devtk codegen tenant-controller # an example + +function gen_for() { + local project="$1" + for types_fn in $(find $project/pkg/apis -mindepth 3 -maxdepth 3 -name types.go); do + local apiname="$(dirname ${types_fn##$project/pkg/apis/})" + local apiver="$(basename $apiname)" + local apipkg="sigs.k8s.io/multi-tenancy/poc/$project/pkg/apis/$apiname" + local clientpkg="sigs.k8s.io/multi-tenancy/poc/$project/pkg/clients/$(dirname $apiname)" + echo "deepcopy-gen $apipkg" && { + deepcopy-gen -h "$TOOLS_DIR/lib/header.go.txt" -i "$apipkg" -O zz_generated.deepcopy + } + echo "client-gen $apipkg" && { + rm -fr "${clientpkg##sigs.k8s.io/multi-tenancy/poc/}/clientset" + client-gen -h "$TOOLS_DIR/lib/header.go.txt" -n "$apiver" -p "$clientpkg/clientset" \ + --input-base "" --input "$apipkg" + } + echo "lister-gen $apipkg" && { + rm -fr "${clientpkg##sigs.k8s.io/multi-tenancy/poc/}/listers" + lister-gen -h "$TOOLS_DIR/lib/header.go.txt" -i "$apipkg" -p "$clientpkg/listers" + } + echo "informer-gen $apipkg" && { + rm -fr "${clientpkg##sigs.k8s.io/multi-tenancy/poc/}/informers" + informer-gen -h "$TOOLS_DIR/lib/header.go.txt" -i "$apipkg" -p "$clientpkg/informers" \ + --versioned-clientset-package "$clientpkg/clientset/$apiver" \ + --listers-package "$clientpkg/listers" + } + done +} + +function cmd_run() { + cd $REPO_ROOT/poc + if [ $# -gt 0 ]; then + for arg; do gen_for "$arg"; done + else + for d in *; do + test -d "$d" || continue + test -d "$d/pkg/apis" || continue + gen_for "$d" + done + fi +} diff --git a/tools/lib/devtk/cmd-setup.sh b/tools/lib/devtk/cmd-setup.sh new file mode 100644 index 000000000..358f8a3eb --- /dev/null +++ b/tools/lib/devtk/cmd-setup.sh @@ -0,0 +1,30 @@ +# Copyright 2018 The Kubernetes Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Usage: +# devtk setup + +function cmd_run() { + set -x + # get packages required by code-generator + go get k8s.io/apimachinery/pkg/apis/meta/v1 + go get k8s.io/api/core/v1 + go get k8s.io/api/rbac/v1 + # install code-generator + go install k8s.io/code-generator/cmd/... + # recreate the symbolic link + rm -f "$GOPATH/src/sigs.k8s.io/multi-tenancy" + mkdir -p "$GOPATH/src/sigs.k8s.io" + ln -s "$REPO_ROOT" "$GOPATH/src/sigs.k8s.io/multi-tenancy" +} diff --git a/tools/lib/functions.sh b/tools/lib/functions.sh new file mode 100644 index 000000000..54bb2e25f --- /dev/null +++ b/tools/lib/functions.sh @@ -0,0 +1,34 @@ +# Copyright 2018 The Kubernetes Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +export TOOLS_DIR=$REPO_ROOT/tools + +function fatal() { + echo "$@" >&2 + exit 1 +} + +function cmdlet_run() { + local kit="$1" cmd="$2" + shift; shift + + local cmd_script="$TOOLS_DIR/lib/$kit/cmd-$cmd.sh" + test -f "$cmd_script" || fatal "unknown command $cmd" + + . "$cmd_script" + + cmd_run "$@" +} + +set -e diff --git a/tools/lib/header.go.txt b/tools/lib/header.go.txt new file mode 100644 index 000000000..e955cd083 --- /dev/null +++ b/tools/lib/header.go.txt @@ -0,0 +1,10 @@ +// Copyright 2017 The Kubernetes Authors. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License.