Skip to content

Commit

Permalink
Identity Controller Boilerplate
Browse files Browse the repository at this point in the history
At present, when provisioning in a cluster, it blocks a long time
waiting for OpenStack to do what it needs to do.  This has a knock on
effect for UX in that said delay is visible in the UI and CLI tools.
This lays down the groundwork to make this asychronous so we don't hold
up uer interaction, but we do cluster provisioning.  This is a template
also for phyiscal network provisioning that takes even longer, and
causes request timeouts that need to be avoided.
  • Loading branch information
spjmurray committed Aug 8, 2024
1 parent b4b82f1 commit cf8049e
Show file tree
Hide file tree
Showing 22 changed files with 427 additions and 4 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ REVISION := $(shell git rev-parse HEAD)
# for your host's architecture. The latter are going to run in Kubernetes, so
# want to be amd64.
CONTROLLERS = \
unikorn-region-controller
unikorn-region-controller \
unikorn-identity-controller

# Release will do cross compliation of all images for the 'all' target.
# Note we aren't fucking about with docker here because that opens up a
Expand Down
50 changes: 50 additions & 0 deletions charts/region/crds/region.unikorn-cloud.org_identities.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ spec:
- projectID
- userID
type: object
pause:
description: Pause, if true, will inhibit reconciliation.
type: boolean
provider:
description: Provider defines the provider type.
enum:
Expand Down Expand Up @@ -116,6 +119,53 @@ spec:
- provider
type: object
status:
properties:
conditions:
description: Current service state of a cluster manager.
items:
description: |-
Condition is a generic condition type for use across all resource types.
It's generic so that the underlying controller-manager functionality can
be shared across all resources.
properties:
lastTransitionTime:
description: Last time the condition transitioned from one status
to another.
format: date-time
type: string
message:
description: Human-readable message indicating details about
last transition.
type: string
reason:
description: Unique, one-word, CamelCase reason for the condition's
last transition.
enum:
- Provisioning
- Provisioned
- Cancelled
- Errored
- Deprovisioning
- Deprovisioned
type: string
status:
description: |-
Status is the status of the condition.
Can be True, False, Unknown.
type: string
type:
description: Type is the type of the condition.
enum:
- Available
type: string
required:
- lastTransitionTime
- message
- reason
- status
- type
type: object
type: array
type: object
required:
- spec
Expand Down
4 changes: 4 additions & 0 deletions charts/region/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ Create the container images
{{- .Values.image | default (printf "%s/unikorn-region-controller:%s" (include "unikorn.defaultRepositoryPath" .) (.Values.tag | default .Chart.Version)) }}
{{- end }}

{{- define "unikorn.identityControllerImage" -}}
{{- .Values.identityController.image | default (printf "%s/unikorn-identity-controller:%s" (include "unikorn.defaultRepositoryPath" .) (.Values.tag | default .Chart.Version)) }}
{{- end }}

{{/*
Create image pull secrets
*/}}
Expand Down
30 changes: 30 additions & 0 deletions charts/region/templates/identity-controller/clusterrole.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: unikorn-identity-controller
labels:
{{- include "unikorn.labels" . | nindent 4 }}
rules:
# Orchestrate Unikorn resources (my job).
- apiGroups:
- region.unikorn-cloud.org
resources:
- identities
verbs:
- list
- watch
- patch
- update
- apiGroups:
- region.unikorn-cloud.org
resources:
- identities/status
verbs:
- update
- apiGroups:
- ""
resources:
- secrets
verbs:
- list
- watch
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: unikorn-identity-controller
labels:
{{- include "unikorn.labels" . | nindent 4 }}
subjects:
- kind: ServiceAccount
namespace: {{ .Release.Namespace }}
name: unikorn-identity-controller
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: unikorn-identity-controller
38 changes: 38 additions & 0 deletions charts/region/templates/identity-controller/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: unikorn-identity-controller
labels:
{{- include "unikorn.labels" . | nindent 4 }}
spec:
replicas: 1
selector:
matchLabels:
app: unikorn-identity-controller
template:
metadata:
labels:
app: unikorn-identity-controller
spec:
containers:
- name: unikorn-identity-controller
image: {{ include "unikorn.identityControllerImage" . }}
ports:
- name: http
containerPort: 6080
- name: prometheus
containerPort: 8080
- name: pprof
containerPort: 6060
resources:
requests:
cpu: "50m"
memory: 50Mi
limits:
cpu: "100m"
memory: 100Mi
securityContext:
readOnlyRootFilesystem: true
serviceAccountName: unikorn-identity-controller
securityContext:
runAsNonRoot: true
23 changes: 23 additions & 0 deletions charts/region/templates/identity-controller/role.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: unikorn-identity-controller
labels:
{{- include "unikorn.labels" . | nindent 4 }}
rules:
# Controller prerequisites.
- apiGroups:
- coordination.k8s.io
resources:
- leases
verbs:
- create
- get
- update
- apiGroups:
- ""
resources:
- events
verbs:
- create
- update
14 changes: 14 additions & 0 deletions charts/region/templates/identity-controller/rolebinding.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: unikorn-identity-controller
labels:
{{- include "unikorn.labels" . | nindent 4 }}
subjects:
- kind: ServiceAccount
namespace: {{ .Release.Namespace }}
name: unikorn-identity-controller
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: unikorn-identity-controller
10 changes: 10 additions & 0 deletions charts/region/templates/identity-controller/serviceaccount.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: unikorn-identity-controller
labels:
{{- include "unikorn.labels" . | nindent 4 }}
{{- with ( include "unikorn.imagePullSecrets" . ) }}
imagePullSecrets:
{{ . }}
{{- end }}
5 changes: 5 additions & 0 deletions charts/region/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ organization: unikorn-cloud
# Allows override of the global default image.
# image:

# Identity controller configuration.
identityController:
# Allow override of the identity controller image.
image:

# Sets the DNS hosts/X.509 Certs.
region:
host: region.unikorn-cloud.org
Expand Down
27 changes: 27 additions & 0 deletions cmd/unikorn-identity-controller/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
Copyright 2022-2024 EscherCloud.
Copyright 2024 the Unikorn 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 (
"github.com/unikorn-cloud/core/pkg/manager"
"github.com/unikorn-cloud/region/pkg/managers/identity"
)

func main() {
manager.Run(&identity.Factory{})
}
2 changes: 2 additions & 0 deletions docker/unikorn-identity-controller/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!bin/*-linux-gnu/unikorn-identity-controller
8 changes: 8 additions & 0 deletions docker/unikorn-identity-controller/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM gcr.io/distroless/static:nonroot

# This is implcitly created by 'docker buildx build'
ARG TARGETARCH

COPY bin/${TARGETARCH}-linux-gnu/unikorn-identity-controller /

ENTRYPOINT ["/unikorn-identity-controller"]
1 change: 0 additions & 1 deletion docker/unikorn-region-controller/.dockerignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
*
!bin/*-linux-gnu/unikorn-region-controller
!hack/passwd.nonroot
1 change: 0 additions & 1 deletion docker/unikorn-region-controller/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ FROM gcr.io/distroless/static:nonroot
# This is implcitly created by 'docker buildx build'
ARG TARGETARCH

# Required as we are talking to Openstack public endpoints.
COPY bin/${TARGETARCH}-linux-gnu/unikorn-region-controller /

ENTRYPOINT ["/unikorn-region-controller"]
9 changes: 9 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,14 @@ require (

require (
github.com/apapsch/go-jsonmerge/v2 v2.0.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/coreos/go-oidc/v3 v3.11.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/emicklei/go-restful/v3 v3.12.1 // indirect
github.com/evanphx/json-patch/v5 v5.9.0 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/go-jose/go-jose/v3 v3.0.3 // indirect
github.com/go-jose/go-jose/v4 v4.0.2 // indirect
github.com/go-logr/logr v1.4.2 // indirect
Expand All @@ -38,6 +41,7 @@ require (
github.com/go-openapi/jsonreference v0.21.0 // indirect
github.com/go-openapi/swag v0.23.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/gnostic-models v0.6.8 // indirect
github.com/google/go-cmp v0.6.0 // indirect
Expand All @@ -60,6 +64,10 @@ require (
github.com/perimeterx/marshmallow v1.1.5 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v1.19.1 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.55.0 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.28.0 // indirect
go.opentelemetry.io/otel/metric v1.28.0 // indirect
go.opentelemetry.io/proto/otlp v1.3.1 // indirect
Expand All @@ -73,6 +81,7 @@ require (
golang.org/x/term v0.22.0 // indirect
golang.org/x/text v0.16.0 // indirect
golang.org/x/time v0.5.0 // indirect
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240708141625-4ad9e859172b // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240708141625-4ad9e859172b // indirect
google.golang.org/grpc v1.65.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ go.opentelemetry.io/proto/otlp v1.3.1 h1:TrMUixzpM0yuc/znrFTP9MMRh8trP93mkCiDVeX
go.opentelemetry.io/proto/otlp v1.3.1/go.mod h1:0X1WI4de4ZsLrrJNLAQbFeLCm3T7yBkR0XqQ7niQU+8=
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
go.uber.org/mock v0.4.0 h1:VcM4ZOtdbR4f6VXfiOpwpVJDL6lCReaZ6mw31wqh7KU=
go.uber.org/mock v0.4.0/go.mod h1:a6FSlNadKUHUa9IP5Vyt1zh4fC7uAwxMutEAscFbkZc=
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8=
Expand Down
48 changes: 48 additions & 0 deletions pkg/apis/unikorn/v1alpha1/helpers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
Copyright 2024 the Unikorn 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 (
unikornv1core "github.com/unikorn-cloud/core/pkg/apis/unikorn/v1alpha1"

corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/labels"
)

// Paused implements the ReconcilePauser interface.
func (c *Identity) Paused() bool {
return c.Spec.Pause
}

// StatusConditionRead scans the status conditions for an existing condition whose type
// matches.
func (c *Identity) StatusConditionRead(t unikornv1core.ConditionType) (*unikornv1core.Condition, error) {
return unikornv1core.GetCondition(c.Status.Conditions, t)
}

// StatusConditionWrite either adds or updates a condition in the cluster manager status.
// If the condition, status and message match an existing condition the update is
// ignored.
func (c *Identity) StatusConditionWrite(t unikornv1core.ConditionType, status corev1.ConditionStatus, reason unikornv1core.ConditionReason, message string) {
unikornv1core.UpdateCondition(&c.Status.Conditions, t, status, reason, message)
}

// ResourceLabels generates a set of labels to uniquely identify the resource
// if it were to be placed in a single global namespace.
func (c *Identity) ResourceLabels() (labels.Set, error) {
return nil, nil
}
Loading

0 comments on commit cf8049e

Please sign in to comment.