Skip to content

Commit

Permalink
feat(Plane): add CRD and dependent resources (#325)
Browse files Browse the repository at this point in the history
  • Loading branch information
kosmoz committed Sep 21, 2023
1 parent 0af0def commit c031e44
Show file tree
Hide file tree
Showing 30 changed files with 1,619 additions and 1 deletion.
279 changes: 279 additions & 0 deletions deploy/crd/planes.glasskube.eu-v1.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,279 @@
# Generated by Fabric8 CRDGenerator, manual edits might get overwritten!
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: planes.glasskube.eu
spec:
group: glasskube.eu
names:
kind: Plane
plural: planes
singular: plane
scope: Namespaced
versions:
- name: v1alpha1
schema:
openAPIV3Schema:
properties:
spec:
properties:
host:
type: string
registrationEnabled:
type: boolean
defaultUser:
properties:
email:
type: string
password:
type: string
required:
- email
- password
type: object
frontend:
properties:
resources:
nullable: true
properties:
claims:
items:
properties:
name:
type: string
type: object
type: array
limits:
additionalProperties:
anyOf:
- type: integer
- type: string
x-kubernetes-int-or-string: true
type: object
requests:
additionalProperties:
anyOf:
- type: integer
- type: string
x-kubernetes-int-or-string: true
type: object
type: object
type: object
space:
properties:
resources:
nullable: true
properties:
claims:
items:
properties:
name:
type: string
type: object
type: array
limits:
additionalProperties:
anyOf:
- type: integer
- type: string
x-kubernetes-int-or-string: true
type: object
requests:
additionalProperties:
anyOf:
- type: integer
- type: string
x-kubernetes-int-or-string: true
type: object
type: object
type: object
api:
properties:
concurrency:
type: integer
resources:
nullable: true
properties:
claims:
items:
properties:
name:
type: string
type: object
type: array
limits:
additionalProperties:
anyOf:
- type: integer
- type: string
x-kubernetes-int-or-string: true
type: object
requests:
additionalProperties:
anyOf:
- type: integer
- type: string
x-kubernetes-int-or-string: true
type: object
type: object
type: object
beatWorker:
properties:
resources:
nullable: true
properties:
claims:
items:
properties:
name:
type: string
type: object
type: array
limits:
additionalProperties:
anyOf:
- type: integer
- type: string
x-kubernetes-int-or-string: true
type: object
requests:
additionalProperties:
anyOf:
- type: integer
- type: string
x-kubernetes-int-or-string: true
type: object
type: object
type: object
worker:
properties:
concurrency:
type: integer
resources:
nullable: true
properties:
claims:
items:
properties:
name:
type: string
type: object
type: array
limits:
additionalProperties:
anyOf:
- type: integer
- type: string
x-kubernetes-int-or-string: true
type: object
requests:
additionalProperties:
anyOf:
- type: integer
- type: string
x-kubernetes-int-or-string: true
type: object
type: object
type: object
smtp:
properties:
host:
type: string
port:
type: integer
fromAddress:
type: string
authSecret:
properties:
name:
type: string
type: object
tlsEnabled:
type: boolean
required:
- host
- fromAddress
- authSecret
type: object
s3:
properties:
bucket:
type: string
accessKeySecret:
properties:
key:
type: string
name:
type: string
optional:
type: boolean
type: object
secretKeySecret:
properties:
key:
type: string
name:
type: string
optional:
type: boolean
type: object
region:
type: string
endpoint:
nullable: true
type: string
usePathStyle:
nullable: true
type: boolean
required:
- bucket
- accessKeySecret
- secretKeySecret
- region
type: object
required:
- host
type: object
status:
properties:
frontend:
properties:
ready:
type: boolean
type: object
space:
properties:
ready:
type: boolean
type: object
api:
properties:
ready:
type: boolean
type: object
beatWorker:
properties:
ready:
type: boolean
type: object
worker:
properties:
ready:
type: boolean
type: object
database:
properties:
ready:
type: boolean
type: object
redis:
properties:
ready:
type: boolean
type: object
type: object
type: object
served: true
storage: true
subresources:
status: {}
4 changes: 3 additions & 1 deletion operator/src/main/kotlin/eu/glasskube/operator/Labels.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ object Labels {
fun resourceLabelSelector(
name: String,
instance: String,
partOf: String? = null
partOf: String? = null,
component: String? = null
) = mutableMapOf(
NAME to name,
INSTANCE to instance
).also {
if (partOf != null) it += PART_OF to partOf
if (component != null) it += COMPONENT to component
}.toMap()
}
86 changes: 86 additions & 0 deletions operator/src/main/kotlin/eu/glasskube/operator/apps/plane/Plane.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package eu.glasskube.operator.apps.plane

import eu.glasskube.operator.Labels
import eu.glasskube.operator.generic.dependent.postgres.PostgresNameMapper
import eu.glasskube.operator.generic.dependent.redis.RedisNameMapper
import io.fabric8.kubernetes.api.model.Namespaced
import io.fabric8.kubernetes.client.CustomResource
import io.fabric8.kubernetes.model.annotation.Group
import io.fabric8.kubernetes.model.annotation.Plural
import io.fabric8.kubernetes.model.annotation.Version

@Group("glasskube.eu")
@Version("v1alpha1")
@Plural("planes")
class Plane : CustomResource<PlaneSpec, PlaneStatus>(), Namespaced {
object Redis : RedisNameMapper<Plane>() {
private const val NAME = "redis"
private const val VERSION = "7.2.1"

override fun getName(primary: Plane) = "${primary.genericResourceName}-$NAME"

override fun getLabels(primary: Plane) =
Labels.resourceLabels(APP_NAME, primary.metadata.name, version = VERSION, component = NAME)

override fun getLabelSelector(primary: Plane) =
Labels.resourceLabelSelector(APP_NAME, primary.metadata.name, component = NAME)

override fun getVersion(primary: Plane) = VERSION
}

object Postgres : PostgresNameMapper<Plane>() {
override fun getName(primary: Plane) = "${primary.genericResourceName}-db"
override fun getLabels(primary: Plane) =
Labels.resourceLabels(APP_NAME, primary.metadata.name, component = "database")

override fun getDatabaseName(primary: Plane) = "plane"
}

internal companion object {
const val APP_NAME = "plane"
const val APP_VERSION = "v0.12.2-dev"
const val FRONTEND_NAME = "frontend"
const val FRONTEND_IMAGE = "makeplane/plane-$FRONTEND_NAME:$APP_VERSION"
const val SPACE_NAME = "deploy"
const val SPACE_IMAGE = "makeplane/plane-$SPACE_NAME:$APP_VERSION"
const val BACKEND_NAME = "backend"
const val BACKEND_IMAGE = "makeplane/plane-$BACKEND_NAME:$APP_VERSION"
const val API_NAME = "api"
const val WORKER_NAME = "worker"
const val BEAT_WORKER_NAME = "beat-worker"
}
}

private val frontendComponentLabel = Labels.COMPONENT to Plane.FRONTEND_NAME
private val spacesComponentLabel = Labels.COMPONENT to Plane.SPACE_NAME
private val apiComponentLabel = Labels.COMPONENT to Plane.API_NAME
private val workerComponentLabel = Labels.COMPONENT to Plane.WORKER_NAME
private val beatWorkerComponentLabel = Labels.COMPONENT to Plane.BEAT_WORKER_NAME

internal val Plane.genericResourceName get() = "${Plane.APP_NAME}-${metadata.name}"
internal val Plane.genericResourceLabels
get() = Labels.resourceLabels(Plane.APP_NAME, metadata.name, version = Plane.APP_VERSION)
internal val Plane.genericResourceLabelSelector
get() = Labels.resourceLabelSelector(Plane.APP_NAME, metadata.name)

internal val Plane.frontendResourceName get() = "$genericResourceName-${Plane.FRONTEND_NAME}"
internal val Plane.frontendResourceLabels get() = genericResourceLabels + frontendComponentLabel
internal val Plane.frontendResourceLabelSelector get() = genericResourceLabelSelector + frontendComponentLabel

internal val Plane.spaceResourceName get() = "$genericResourceName-${Plane.SPACE_NAME}"
internal val Plane.spaceResourceLabels get() = genericResourceLabels + spacesComponentLabel
internal val Plane.spaceResourceLabelSelector get() = genericResourceLabelSelector + spacesComponentLabel

internal val Plane.backendResourceName get() = "$genericResourceName-${Plane.BACKEND_NAME}"

internal val Plane.apiResourceName get() = "$genericResourceName-${Plane.API_NAME}"
internal val Plane.apiResourceLabels get() = genericResourceLabels + apiComponentLabel
internal val Plane.apiResourceLabelSelector get() = genericResourceLabelSelector + apiComponentLabel

internal val Plane.workerResourceName get() = "$genericResourceName-${Plane.WORKER_NAME}"
internal val Plane.workerResourceLabels get() = genericResourceLabels + workerComponentLabel
internal val Plane.workerResourceLabelSelector get() = genericResourceLabelSelector + workerComponentLabel

internal val Plane.beatWorkerResourceName get() = "$genericResourceName-${Plane.BEAT_WORKER_NAME}"
internal val Plane.beatWorkerResourceLabels get() = genericResourceLabels + beatWorkerComponentLabel
internal val Plane.beatWorkerResourceLabelSelector get() = genericResourceLabelSelector + beatWorkerComponentLabel
Loading

0 comments on commit c031e44

Please sign in to comment.