Skip to content

Commit

Permalink
SB operator.
Browse files Browse the repository at this point in the history
  • Loading branch information
badri committed Dec 17, 2023
1 parent 9c59927 commit ad628cd
Show file tree
Hide file tree
Showing 6 changed files with 309 additions and 4 deletions.
11 changes: 7 additions & 4 deletions addons.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ microk8s-addons:
supported_architectures:
- arm64
- amd64

#TODO: flux
#TODO: cluster issuer, clusterstore, default regcreds
#TODO: shapeblock operator
- name: "sb-operator"
description: "Shapeblock operator"
version: "1.0.0"
check_status: "deployment.apps/sb-operator"
supported_architectures:
- arm64
- amd64
18 changes: 18 additions & 0 deletions addons/sb-operator/disable
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env python3

import click
import os
import subprocess

KUBECTL = os.path.expandvars("$SNAP/microk8s-kubectl.wrapper")

@click.command()
def main():
click.echo("Deleting sb-operator")
subprocess.check_call([
KUBECTL, "delete", "deploy", "sb-operator"
])
click.echo("Deleting sb-operator")

if __name__ == "__main__":
main()
39 changes: 39 additions & 0 deletions addons/sb-operator/enable
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env python3

import click
import os
import subprocess
from string import Template
import base64

KUBECTL = os.path.expandvars("$SNAP/microk8s-kubectl.wrapper")

# Define the cluster_issuer template with a placeholder for email

@click.command()
@click.option("--sb_url", required=True, type=str)
@click.option("--cluster_uuid", required=True, type=str)
@click.option("--registry", required=True, type=str)
@click.option("--username", required=True, type=str)
@click.option("--password", required=True, type=str)
def main(sb_url, cluster_uuid, registry, username, password):
click.echo("Creating SB operator")
sb_operator_template = Template(open('.yaml').read())
sb_operator_manifest = sb_operator_template.substitute(sb_url=sb_url, cluster_uuid=cluster_uuid)
subprocess.run([KUBECTL, "apply", "-f", "-"], input=sb_operator_manifest.encode())
click.echo("Created SB operator")

click.echo("Creating kpack artefacts")
kpack_artefacts = open('kpack_artefacts.yaml').read()
subprocess.run([KUBECTL, "apply", "-f", "-"], input=kpack_artefacts.encode())
click.echo("Created kpack artefacts")

click.echo("Creating registry credentials")
regcreds_template = Template(open('regcreds.yaml').read())
auth = base64.b64encode(f"{username}:{password}".encode()).decode('utf-8')
regcreds_manifest = regcreds_template.substitute(registry_url=registry, auth=auth)
subprocess.run([KUBECTL, "apply", "-f", "-"], input=regcreds_manifest.encode())
click.echo("Created registry credentials")

if __name__ == "__main__":
main()
45 changes: 45 additions & 0 deletions addons/sb-operator/kpack-artefacts.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
apiVersion: kpack.io/v1alpha2
kind: ClusterStack
metadata:
name: base
spec:
id: "io.buildpacks.stacks.jammy"
buildImage:
image: "paketobuildpacks/build-jammy-full"
runImage:
image: "paketobuildpacks/run-jammy-full"
---
apiVersion: kpack.io/v1alpha2
kind: ClusterStore
metadata:
name: paketo-django
spec:
sources:
- image: index.docker.io/paketobuildpacks/python
---
apiVersion: kpack.io/v1alpha2
kind: ClusterStore
metadata:
name: paketo-node
spec:
sources:
- image: index.docker.io/paketobuildpacks/nodejs
---
apiVersion: kpack.io/v1alpha2
kind: ClusterStore
metadata:
name: sb-drupal
spec:
sources:
- image: index.docker.io/paketobuildpacks/ca-certificates
- image: index.docker.io/paketobuildpacks/php-dist
- image: index.docker.io/paketobuildpacks/composer
- image: registry.gitlab.com/shapeblock-buildpacks/composer-install:0.0.1
- image: index.docker.io/paketobuildpacks/nginx
- image: index.docker.io/paketobuildpacks/php-fpm
- image: registry.gitlab.com/shapeblock-buildpacks/php-nginx:0.0.1
- image: index.docker.io/paketobuildpacks/php-start
- image: index.docker.io/paketobuildpacks/nodejs
- image: index.docker.io/paketobuildpacks/procfile
- image: ghcr.io/fagiani/buildpacks/fagiani_apt:0.2.5
- image: registry.gitlab.com/shapeblock-buildpacks/chmod:0.0.2
7 changes: 7 additions & 0 deletions addons/sb-operator/regcreds.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: v1
data:
.dockerconfigjson: {"auths":{"$registry_url":{""auth":"$auth"}}}
kind: Secret
metadata:
name: registry-creds
type: kubernetes.io/dockerconfigjson
193 changes: 193 additions & 0 deletions addons/sb-operator/sb-operator.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: applications.dev.shapeblock.com
spec:
group: dev.shapeblock.com
names:
kind: Application
listKind: ApplicationList
shortNames:
- app
- apps
plural: applications
singular: application
scope: Namespaced
versions:
- name: v1alpha1
schema:
openAPIV3Schema:
description: Application is the Schema for the applications API
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:
description: ApplicationSpec defines the desired state of Application
properties:
stack:
type: string
enum: [php, java, python, node, go, ruby]
chart:
properties:
name:
type: string
repo:
type: string
values:
type: string
version:
type: string
build:
type: array
items:
type: object
properties:
name:
type: string
value:
type: string
type: object
git:
properties:
ref:
type: string
repo:
type: string
type: object
serviceAccount:
type: string
tag:
type: string
type: object
status:
x-kubernetes-preserve-unknown-fields: true
description: ApplicationStatus defines the observed state of Application
properties:
deployed:
description: 'INSERT ADDITIONAL STATUS FIELD - define observed state
of cluster Important: Run "make" to regenerate code after modifying
this file'
type: boolean
image:
type: string
ref:
type: string
type: object
type: object
served: true
storage: true
subresources:
status: {}
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: projects.dev.shapeblock.com
spec:
group: dev.shapeblock.com
names:
kind: Project
listKind: ProjectList
plural: projects
singular: project
scope: Cluster
versions:
- name: v1alpha1
schema:
openAPIV3Schema:
type: object
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:
name:
type: string
description: The human readable name of the project.
description:
type: string
description: What this project is about.
type: object
served: true
storage: true
subresources:
status: {}
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: sb-admin
namespace: default
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: sb-admin
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: cluster-admin
subjects:
- kind: ServiceAccount
name: sb-admin
namespace: default
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: sb-operator
spec:
replicas: 1
strategy:
type: Recreate
selector:
matchLabels:
application: sb-operator
template:
metadata:
labels:
application: sb-operator
spec:
serviceAccountName: sb-admin
containers:
- name: sb-operator
image: shapeblock/sb-operator:09-oct-2023-11.32
imagePullPolicy: Always
env:
- name: SB_URL
value: "$sb_url"
- name: CLUSTER_ID
value: "$cluster_uuid"

0 comments on commit ad628cd

Please sign in to comment.