Skip to content

Commit

Permalink
TK-65403 disable custom rest backend
Browse files Browse the repository at this point in the history
- custom rest does not register any resource verbs kubernetes-sigs/apiserver-builder-alpha#551
- template etcd variables
- use temp dir by default
- test example apiserver in PR build
  • Loading branch information
drewwells committed Oct 25, 2020
1 parent 893e7c7 commit 839c3fd
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 12 deletions.
19 changes: 11 additions & 8 deletions helm-charts/example-apiserver/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@ spec:
containers:
# Insecure etcd to chat with
- name: etcd
image: quay.io/coreos/etcd:v3.4.13
imagePullPolicy: IfNotPresent
image: {{ .Values.etcd.image.repository }}:{{ .Values.etcd.image.tag }}
imagePullPolicy: {{ .Values.etcd.imagePullPolicy }}
command:
- etcd
- --listen-client-urls=http://0.0.0.0:2379
- --advertise-client-urls=http://localhost:2379
- --listen-client-urls={{ .Values.etcd.svc.protocol }}://0.0.0.0:{{ .Values.etcd.svc.port }}
- --advertise-client-urls={{ .Values.etcd.svc.protocol }}://{{ .Values.etcd.svc.name }}:{{ .Values.etcd.svc.port }}
ports:
- containerPort: 2379
- containerPort: {{ .Values.etcd.svc.port }}
readinessProbe:
httpGet:
port: 2379
port: {{ .Values.etcd.svc.port }}
path: /health
failureThreshold: 1
initialDelaySeconds: 10
Expand All @@ -50,7 +50,7 @@ spec:
timeoutSeconds: 2
livenessProbe:
httpGet:
port: 2379
port: {{ .Values.etcd.svc.port }}
path: /health
failureThreshold: 3
initialDelaySeconds: 10
Expand Down Expand Up @@ -84,15 +84,18 @@ spec:
- "./apiserver"
args:
- "--delegated-auth=false"
- --etcd-servers=http://127.0.0.1:2379
- --etcd-servers=http://127.0.0.1:{{ .Values.etcd.svc.port }}
- "--tls-cert-file=/apiserver.local.config/certificates/tls.crt"
- "--tls-private-key-file=/apiserver.local.config/certificates/tls.key"
- "-v=10"
- name: controller
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
command:
- "./controller-manager"
args:
- "-v=10"
args:
resources:
{{- toYaml .Values.manager.resources | nindent 12 }}
{{- with .Values.nodeSelector }}
Expand Down
11 changes: 11 additions & 0 deletions helm-charts/example-apiserver/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@ image:
# Overrides the image tag whose default is the chart appVersion.
tag: ""

etcd:
image:
repository: quay.io/coreos/etcd
tag: v3.4.13
imagePullPolicy: IfNotPresent
svc:
protocol: http
name: localhost
port: 2379


imagePullSecrets: []
nameOverride: ""
fullnameOverride: ""
Expand Down
2 changes: 2 additions & 0 deletions test/apiserver/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ require (
github.com/spf13/pflag v1.0.5
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5 // indirect
k8s.io/api v0.19.2
github.com/spf13/pflag v1.0.5
golang.org/x/net v0.0.0-20200707034311-ab3426394381
k8s.io/apimachinery v0.19.2
k8s.io/apiserver v0.19.2
k8s.io/client-go v0.19.2
Expand Down
10 changes: 10 additions & 0 deletions test/apiserver/makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
IMAGE_TAG ?= $(shell git describe --tags --always)
IMAGE_REPO ?= infoblox/konk-apiserver-example
IMAGE := $(IMAGE_REPO):$(IMAGE_TAG)
TEST_ENV := GO111MODULE=off

APISERVER_BOOT_VERSION := v1.18.0
APISERVER_BOOT := bin/apiserver-boot
Expand Down Expand Up @@ -58,6 +59,15 @@ push: image .push-${IMAGE_TAG}

build: bin/apiserver bin/controller-manager

vendor:
go mod vendor

# Tests run better if you disable GO111MODULE
test: vendor test

suite-test:
${TEST_ENV} cd pkg/controller/contact; go test -v

# go list can build the dependency needed here
.PHONY: bin/controller-manager
bin/controller-manager:
Expand Down
3 changes: 2 additions & 1 deletion test/apiserver/pkg/apis/example/contact_rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

// See https://github.com/kubernetes-sigs/apiserver-builder-alpha/pull/533/files#diff-163ee78893222e626ff355526b0c37102559d5c551b0d4c6851e4da2c1ef06f9R12
func NewContactREST(getter generic.RESTOptionsGetter) rest.Storage {
klog.Infof("new_contact_rest root-directory=%s", rootDir)
gr := schema.GroupResource{
Group: "example.infoblox.com",
Resource: "contacts",
Expand All @@ -22,7 +23,7 @@ func NewContactREST(getter generic.RESTOptionsGetter) rest.Storage {
bugged := filepath.NewFilepathREST(
gr,
opt.StorageConfig.Codec,
"/data/",
rootDir,
true,
func() runtime.Object { return &Contact{} },
func() runtime.Object { return &ContactList{} },
Expand Down
24 changes: 24 additions & 0 deletions test/apiserver/pkg/apis/example/flags.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package example

import (
"io/ioutil"
"log"

"github.com/spf13/pflag"
)

var (
rootDir string = "/data"
)

func init() {

dir, err := ioutil.TempDir("", "contact_controller_suite")
if err != nil {
log.Fatal(err)
}

flags := pflag.NewFlagSet("example", pflag.ExitOnError)
flags.StringVar(&rootDir, "root-dir", dir, "root directory for file storage")
pflag.CommandLine.AddFlagSet(flags)
}
4 changes: 3 additions & 1 deletion test/apiserver/pkg/apis/example/v1alpha1/contact_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import (
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// Contact
// Custom backends do not work, see https://github.com/kubernetes-sigs/apiserver-builder-alpha/issues/551
// // resource:path=contacts,strategy=ContactStrategy,rest=ContactREST
// +k8s:openapi-gen=true
// +resource:path=contacts,strategy=ContactStrategy,rest=ContactREST
// +resource:path=contacts,strategy=ContactStrategy
type Contact struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Expand Down
5 changes: 3 additions & 2 deletions test/apiserver/pkg/controller/contact/contact_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,13 @@ type ReconcileContact struct {
scheme *runtime.Scheme
}

// +kubebuilder:rbac:groups=example.infoblox.com,resources=contacts,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=example.infoblox.com,resources=contacts/status,verbs=get;update;patch

// Reconcile reads that state of the cluster for a Contact object and makes changes based on the state read
// and what is in the Contact.Spec
// TODO(user): Modify this Reconcile function to implement your Controller logic. The scaffolding writes
// a Deployment as an example
// +kubebuilder:rbac:groups=example.infoblox.com,resources=contacts,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=example.infoblox.com,resources=contacts/status,verbs=get;update;patch
func (r *ReconcileContact) Reconcile(request reconcile.Request) (reconcile.Result, error) {
// Fetch the Contact instance
instance := &examplev1alpha1.Contact{}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package contact

import (
"io/ioutil"
"log"
"os"
"sync"
"testing"
Expand All @@ -20,10 +22,18 @@ var cfg *rest.Config
func TestMain(m *testing.M) {

env := suite.NewDefaultTestingEnvironment()
dir, err := ioutil.TempDir("", "contact_controller_suite")
if err != nil {
log.Fatal(err)
}

// FIXME: cant override any flags due to test suite
env.AggregatedAPIServerFlags = []string{"--root-dir", dir}
if err := env.StartLocalKubeAPIServer(); err != nil {
stdlog.Fatal(err)
return
}

if err := env.StartLocalAggregatedAPIServer("example.infoblox.com", "v1alpha1"); err != nil {
stdlog.Fatal(err)
return
Expand Down

0 comments on commit 839c3fd

Please sign in to comment.