Skip to content

Commit

Permalink
Merge pull request #15 from appuio/feat/api-server-deploy
Browse files Browse the repository at this point in the history
Add control-API sample deployment
  • Loading branch information
glrf authored Jan 10, 2022
2 parents f7008bc + 3512e46 commit cdde5ec
Show file tree
Hide file tree
Showing 16 changed files with 164 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ COPY control-api /usr/local/bin/

RUN chmod a+x /usr/local/bin/control-api

USER 65532
USER 65532:0
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ generate: ## Generate manifests e.g. CRD, RBAC etc.
# Generate code
go run sigs.k8s.io/controller-tools/cmd/controller-gen object paths="./..."
# Generate CRDs
go run sigs.k8s.io/controller-tools/cmd/controller-gen rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=$(CRD_ROOT_DIR)/v1/base crd:crdVersions=v1
go run sigs.k8s.io/controller-tools/cmd/controller-gen rbac:roleName=control-api webhook paths="./..." output:crd:artifacts:config=$(CRD_ROOT_DIR)/v1/base crd:crdVersions=v1

.PHONY: crd
crd: generate ## Generate CRD to file
Expand Down
2 changes: 2 additions & 0 deletions apis/organization/v1/organization_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"sigs.k8s.io/apiserver-runtime/pkg/builder/resource"
)

// +kubebuilder:rbac:groups="",resources=namespaces,verbs=get;list;watch;create;delete;update

var (
// TypeKey is the label key to identify organization namespaces
TypeKey = "appuio.io/resource.type"
Expand Down
4 changes: 4 additions & 0 deletions apiserver/organization/organization.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
)

// +kubebuilder:rbac:groups="",resources=configmaps,verbs=get;list;watch,resourceNames=extension-apiserver-authentication
// +kubebuilder:rbac:groups="admissionregistration.k8s.io",resources=mutatingwebhookconfigurations;validatingwebhookconfigurations,verbs=get;list;watch
// +kubebuilder:rbac:groups="flowcontrol.apiserver.k8s.io",resources=prioritylevelconfigurations;flowschemas,verbs=get;list;watch

// New returns a new storage provider for Organizations
func New() restbuilder.ResourceHandlerProvider {
return func(s *runtime.Scheme, g genericregistry.RESTOptionsGetter) (rest.Storage, error) {
Expand Down
14 changes: 14 additions & 0 deletions config/deployment/apiservice.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: apiregistration.k8s.io/v1
kind: APIService
metadata:
name: v1.organization.appuio.io
spec:
insecureSkipTLSVerify: true
group: organization.appuio.io
groupPriorityMinimum: 1000
versionPriority: 15
service:
name: apiserver
namespace: control-api
version: v1

41 changes: 41 additions & 0 deletions config/deployment/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: control-api
namespace: control-api
labels:
app: control-api
spec:
selector:
matchLabels:
app: control-api
replicas: 1
template:
metadata:
labels:
app: control-api
spec:
serviceAccountName: control-api
containers:
- name: apiserver
image: ghcr.io/appuio/control-api:latest
imagePullPolicy: IfNotPresent
ports:
- containerPort: 9443
args:
- "--cert-dir=/apiserver.local.config/certificates"
- "--secure-port=9443"
- "--feature-gates=APIPriorityAndFairness=false"
volumeMounts:
- name: apiserver-certs
mountPath: /apiserver.local.config/certificates
resources:
requests:
cpu: 100m
memory: 20Mi
limits:
cpu: 100m
memory: 30Mi
volumes:
- name: apiserver-certs
emptyDir: {}
8 changes: 8 additions & 0 deletions config/deployment/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace: control-api

resources:
- ../namespace
- ../rbac
- deployment.yaml
- service.yaml
- apiservice.yaml
12 changes: 12 additions & 0 deletions config/deployment/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: v1
kind: Service
metadata:
name: apiserver
namespace: control-api
spec:
ports:
- port: 443
protocol: TCP
targetPort: 9443
selector:
app: control-api
2 changes: 2 additions & 0 deletions config/namespace/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
resources:
- namespace.yaml
4 changes: 4 additions & 0 deletions config/namespace/namespace.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apiVersion: v1
kind: Namespace
metadata:
name: control-api
5 changes: 5 additions & 0 deletions config/rbac/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
resources:
- role.yaml
- role_binding.yaml
- role_binding_auth_delegator.yaml
- service_account.yaml
41 changes: 40 additions & 1 deletion config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,38 @@ apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
creationTimestamp: null
name: manager-role
name: control-api
rules:
- apiGroups:
- ""
resourceNames:
- extension-apiserver-authentication
resources:
- configmaps
verbs:
- get
- list
- watch
- apiGroups:
- ""
resources:
- namespaces
verbs:
- create
- delete
- get
- list
- update
- watch
- apiGroups:
- admissionregistration.k8s.io
resources:
- mutatingwebhookconfigurations
- validatingwebhookconfigurations
verbs:
- get
- list
- watch
- apiGroups:
- coordination.k8s.io
resources:
Expand All @@ -15,3 +45,12 @@ rules:
- get
- list
- update
- apiGroups:
- flowcontrol.apiserver.k8s.io
resources:
- flowschemas
- prioritylevelconfigurations
verbs:
- get
- list
- watch
12 changes: 12 additions & 0 deletions config/rbac/role_binding.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: control-api
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: control-api
subjects:
- kind: ServiceAccount
name: control-api
namespace: control-api
12 changes: 12 additions & 0 deletions config/rbac/role_binding_auth_delegator.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: control-api-auth-delegator
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: system:auth-delegator
subjects:
- kind: ServiceAccount
name: control-api
namespace: control-api
5 changes: 5 additions & 0 deletions config/rbac/service_account.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: control-api
namespace: control-api
1 change: 1 addition & 0 deletions local-env/setup-kind.sh
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ kubectl config set-credentials oidc-user \
--exec-arg=--oidc-extra-scope="email offline_access profile openid"
kubectl config set-context --current --user=oidc-user
kubectl apply -k "${script_dir}/../config/crd/apiextensions.k8s.io/v1"
kubectl apply -k "${script_dir}/../config/deployment"

echo =======
echo "Setup finished. To interact with the local dev cluster, set the KUBECONFIG environment variable as follows:"
Expand Down

0 comments on commit cdde5ec

Please sign in to comment.