Skip to content

Commit

Permalink
Add Server Controller part 1 (#71)
Browse files Browse the repository at this point in the history
Adds in a MVP server CRD, and all the necessary controller scaffolding.
  • Loading branch information
nsricardor authored Nov 7, 2024
1 parent 985973b commit eb9f10f
Show file tree
Hide file tree
Showing 20 changed files with 1,106 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ CONTROLLERS = \
unikorn-identity-controller \
unikorn-physical-network-controller \
unikorn-security-group-controller \
unikorn-security-group-rule-controller
unikorn-security-group-rule-controller \
unikorn-server-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
61 changes: 61 additions & 0 deletions charts/region/crds/region.unikorn-cloud.org_openstackservers.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.16.1
name: openstackservers.region.unikorn-cloud.org
spec:
group: region.unikorn-cloud.org
names:
categories:
- unikorn
kind: OpenstackServer
listKind: OpenstackServerList
plural: openstackservers
singular: openstackserver
scope: Namespaced
versions:
- additionalPrinterColumns:
- jsonPath: .metadata.creationTimestamp
name: age
type: date
name: v1alpha1
schema:
openAPIV3Schema:
description: OpenstackServer has no controller, its a database record of state.
properties:
apiVersion:
description: |-
APIVersion defines the versioned schema of this representation of an object.
Servers should convert recognized schemas to the latest internal value, and
may reject unrecognized values.
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
type: string
kind:
description: |-
Kind is a string value representing the REST resource this object represents.
Servers may infer this from the endpoint the client submits requests to.
Cannot be updated.
In CamelCase.
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
type: string
metadata:
type: object
spec:
properties:
publicIPAllocationId:
description: PublicIPAllocationId is the public ip allocation id.
type: string
serverID:
description: ServerID is the server ID.
type: string
type: object
status:
type: object
required:
- spec
type: object
served: true
storage: true
subresources: {}
206 changes: 206 additions & 0 deletions charts/region/crds/region.unikorn-cloud.org_servers.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.16.1
name: servers.region.unikorn-cloud.org
spec:
group: region.unikorn-cloud.org
names:
categories:
- unikorn
kind: Server
listKind: ServerList
plural: servers
singular: server
scope: Namespaced
versions:
- additionalPrinterColumns:
- jsonPath: .status.conditions[?(@.type=="Available")].reason
name: status
type: string
- jsonPath: .metadata.creationTimestamp
name: age
type: date
- jsonPath: .status.publicIP
name: publicIP
type: string
name: v1alpha1
schema:
openAPIV3Schema:
description: Server defines a server beloning to an identity.
properties:
apiVersion:
description: |-
APIVersion defines the versioned schema of this representation of an object.
Servers should convert recognized schemas to the latest internal value, and
may reject unrecognized values.
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
type: string
kind:
description: |-
Kind is a string value representing the REST resource this object represents.
Servers may infer this from the endpoint the client submits requests to.
Cannot be updated.
In CamelCase.
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
type: string
metadata:
type: object
spec:
properties:
flavorID:
description: FlavorID is the flavor ID.
type: string
image:
description: Image defines a set of rules to lookup for the server
image.
properties:
id:
description: ID is the image ID. If specified, it has priority
over the selector.
type: string
selector:
description: Selector defines a set of rules to lookup images.
properties:
os:
description: OS is the operating system of the image.
type: string
version:
description: Version is the version of the image.
type: string
required:
- os
- version
type: object
type: object
x-kubernetes-validations:
- message: at least one of id or selector must be defined
rule: (has(self.id) || has(self.selector))
networks:
description: Networks is the server network configuration.
items:
properties:
physicalNetwork:
properties:
id:
description: ID is the physical network ID.
type: string
required:
- id
type: object
type: object
type: array
pause:
description: Pause, if true, will inhibit reconciliation.
type: boolean
provider:
description: Provider defines the provider type.
enum:
- openstack
type: string
publicIPAllocation:
description: PublicIPAllocation is the server public IP allocation
configuration.
properties:
enabled:
description: Enabled is a flag to enable public IP allocation.
type: boolean
type: object
securityGroups:
description: SecurityGroups is the server security groups.
items:
properties:
id:
description: ID is the security group ID.
type: string
required:
- id
type: object
type: array
tags:
description: |-
Tags are an abitrary list of key/value pairs that a client
may populate to store metadata for the resource.
items:
description: Tag is an arbirary key/value.
properties:
name:
description: Name of the tag.
type: string
value:
description: Value of the tag.
type: string
required:
- name
- value
type: object
type: array
required:
- flavorID
- image
- 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
privateIP:
description: PrivateIP is the private IP address of the server.
type: string
publicIP:
description: PublicIP is the public IP address of the server.
type: string
type: object
required:
- spec
type: object
served: true
storage: true
subresources:
status: {}
4 changes: 4 additions & 0 deletions charts/region/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ Create the container images
{{- .Values.securityGroupRuleController.image | default (printf "%s/unikorn-security-group-rule-controller:%s" (include "unikorn.defaultRepositoryPath" .) (.Values.tag | default .Chart.Version)) }}
{{- end }}

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

{{/*
Create image pull secrets
*/}}
Expand Down
53 changes: 53 additions & 0 deletions charts/region/templates/server-controller/clusterrole.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: unikorn-server-controller
labels:
{{- include "unikorn.labels" . | nindent 4 }}
rules:
# Orchestrate Unikorn resources (my job).
- apiGroups:
- region.unikorn-cloud.org
resources:
- regions
- identities
- openstackidentities
- physicalnetworks
- openstackphysicalnetworks
- securitygroups
- openstacksecuritygroups
verbs:
- list
- watch
- apiGroups:
- region.unikorn-cloud.org
resources:
- servers
verbs:
- list
- watch
- update
- patch
- apiGroups:
- region.unikorn-cloud.org
resources:
- servers/status
verbs:
- update
- apiGroups:
- region.unikorn-cloud.org
resources:
- openstackservers
verbs:
- list
- watch
- create
- update
- delete
- apiGroups:
- ""
resources:
- secrets
verbs:
- list
- watch
14 changes: 14 additions & 0 deletions charts/region/templates/server-controller/clusterrolebinding.yaml
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-server-controller
labels:
{{- include "unikorn.labels" . | nindent 4 }}
subjects:
- kind: ServiceAccount
namespace: {{ .Release.Namespace }}
name: unikorn-server-controller
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: unikorn-server-controller
Loading

0 comments on commit eb9f10f

Please sign in to comment.