diff --git a/examples/kubernetes-yaml-crd/.gitignore b/examples/kubernetes-yaml-crd/.gitignore new file mode 100644 index 00000000..4d8d3e40 --- /dev/null +++ b/examples/kubernetes-yaml-crd/.gitignore @@ -0,0 +1,8 @@ +### Scala an JVM +*.class +*.log +.bsp +.scala-build + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* diff --git a/examples/kubernetes-yaml-crd/Main.scala b/examples/kubernetes-yaml-crd/Main.scala new file mode 100644 index 00000000..8c4509ec --- /dev/null +++ b/examples/kubernetes-yaml-crd/Main.scala @@ -0,0 +1,74 @@ +import besom.* +import besom.api.kubernetes as k8s + +@main def main = Pulumi.run { + + val crd = + k8s.yaml.v2.ConfigGroup( + name = "config-group", + k8s.yaml.v2.ConfigGroupArgs( + yaml = """apiVersion: apiextensions.k8s.io/v1 + |kind: CustomResourceDefinition + |metadata: + | # name must match the spec fields below, and be in the form: . + | name: crontabs.stable.example.com + |spec: + | # group name to use for REST API: /apis// + | group: stable.example.com + | # list of versions supported by this CustomResourceDefinition + | versions: + | - name: v1 + | # Each version can be enabled/disabled by Served flag. + | served: true + | # One and only one version must be marked as the storage version. + | storage: true + | schema: + | openAPIV3Schema: + | type: object + | properties: + | spec: + | type: object + | properties: + | cronSpec: + | type: string + | image: + | type: string + | replicas: + | type: integer + | # either Namespaced or Cluster + | scope: Namespaced + | names: + | # plural name to be used in the URL: /apis/// + | plural: crontabs + | # singular name to be used as an alias on the CLI and for display + | singular: crontab + | # kind is normally the CamelCased singular type. Your resource manifests use this. + | kind: CronTab + | # shortNames allow shorter string to match your resource on the CLI + | shortNames: + | - ct + | """.stripMargin + ) + ) + + val cronTab = + k8s.yaml.v2.ConfigGroup( + name = "cron-tab", + k8s.yaml.v2.ConfigGroupArgs( + yaml = """apiVersion: "stable.example.com/v1" + |kind: CronTab + |metadata: + | name: my-new-cron-object + |spec: + | cronSpec: "* * * * */5" + | image: my-awesome-cron-image + | """.stripMargin + ), + opts = opts(dependsOn = crd) + ) + + Stack.exports( + crdResource = crd.resources, + cronTabResource = cronTab.resources + ) +} diff --git a/examples/kubernetes-yaml-crd/Pulumi.yaml b/examples/kubernetes-yaml-crd/Pulumi.yaml new file mode 100644 index 00000000..1eab2f44 --- /dev/null +++ b/examples/kubernetes-yaml-crd/Pulumi.yaml @@ -0,0 +1,3 @@ +name: kubernetes-yaml-crd +runtime: scala +description: Example of a Kubernetes Application using plain YAML files with custom CRD diff --git a/examples/kubernetes-yaml-crd/README.md b/examples/kubernetes-yaml-crd/README.md new file mode 100644 index 00000000..58d43f55 --- /dev/null +++ b/examples/kubernetes-yaml-crd/README.md @@ -0,0 +1,54 @@ +# Kubernetes application using plain YAML files with custom CRD + +Example based +on [Kubernetes custom resource definitions](https://kubernetes.io/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definitions/). +Uses plain YAML files to create custom CronTab CRD and deploy it to Kubernetes cluster. + +## Prerequisites + +Follow the steps in [Pulumi Installation and +Setup](https://www.pulumi.com/docs/get-started/install/) and [Configuring Pulumi +Kubernetes](https://www.pulumi.com/docs/intro/cloud-providers/kubernetes/setup/) to get set up with +Pulumi and Kubernetes. + +## Running the App + +1. Create a new stack: + + ```sh + $ pulumi stack init + Enter a stack name: dev + ``` + +2. Preview the deployment of the application and perform the deployment: + + ```sh + $ pulumi up + ``` + +3. You can then manage your CronTab objects using kubectl: + + ```sh + $ kubectl get crontab + ``` + Should print a list like this: + ``` + NAME AGE + my-new-cron-object 6s + ``` + +4. You can also view the raw YAML data: + + ```sh + $ kubectl get ct -o yaml + ``` + +5. From there, feel free to experiment. Simply making edits and running pulumi up will incrementally update your + infrastructure. + +6. Once you've finished experimenting, tear down your stack's resources by destroying and removing it: + + ```bash + $ pulumi destroy --yes + $ pulumi stack rm --yes + ``` \ No newline at end of file diff --git a/examples/kubernetes-yaml-crd/project.scala b/examples/kubernetes-yaml-crd/project.scala new file mode 100644 index 00000000..db556c31 --- /dev/null +++ b/examples/kubernetes-yaml-crd/project.scala @@ -0,0 +1,4 @@ +//> using scala "3.3.1" +//> using options -Werror -Wunused:all -Wvalue-discard -Wnonunit-statement +//> using dep "org.virtuslab::besom-core:0.3.1" +//> using dep "org.virtuslab::besom-kubernetes:4.11.0-core.0.3"