Skip to content

Commit

Permalink
Add overlay support to codegen
Browse files Browse the repository at this point in the history
- refactor codegen to allow for the required changes to be made
- add support for overlays in codegen
- add kubernetes overlay for custom resources
  • Loading branch information
pawelprazak committed Feb 28, 2024
1 parent bceafff commit fd8162e
Show file tree
Hide file tree
Showing 34 changed files with 970 additions and 432 deletions.
2 changes: 2 additions & 0 deletions codegen/project.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
//> using dep com.lihaoyi::os-lib:0.9.3
//> using test.dep org.scalameta::munit::1.0.0-M10

//> using exclude "resources/*"

//> using publish.name "besom-codegen"
//> using publish.organization "org.virtuslab"
//> using publish.url "https://github.com/VirtusLab/besom"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package besom.api.kubernetes.apiextensions

import besom.util.interpolator.{*, given}
import besom.types.ResourceType

/** CustomResource represents a resource definition we'd use to create an instance of a Kubernetes CustomResourceDefinition (CRD).
*
* For example, the CoreOS Prometheus operator exposes a CRD `monitoring.coreos.com/ServiceMonitor` to create a `ServiceMonitor`, we'd pass
* a `CustomResourceArgs` containing the `ServiceMonitor` definition to `apiextensions.CustomResource`.
*/
trait CustomResourceLike extends besom.CustomResource:
/** 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.
*
* @see
* [[https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources Kubernetes API Version]]
* @return
*/
def apiVersion: besom.types.Output[String]

/** 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.
*
* @see
* [[https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds Kubernetes Kinds]]
* @return
*/
def kind: besom.types.Output[String]

/** Standard Kubernetes object metadata
*
* @see
* [[https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata Kubernetes Metadata]]
* @return
* the object metadata
*/
def metadata: besom.types.Output[besom.api.kubernetes.meta.v1.outputs.ObjectMeta]
end CustomResourceLike

trait CustomResourceFactory[
R <: besom.api.kubernetes.apiextensions.CustomResourceLike,
A <: besom.api.kubernetes.apiextensions.CustomResourceArgsLike
]:

/** Create a CustomResource resource with the given unique name, arguments, and options.
*
* @param name
* The unique name of the resource.
* @param args
* The arguments to use to populate this resource's properties.
* @param opts
* A bag of options that control this resource's behavior.
*/
def apply(using ctx: besom.types.Context, dd: besom.types.ResourceDecoder[R], ae: besom.types.ArgsEncoder[A])(
name: besom.util.NonEmptyString,
args: A,
opts: besom.ResourceOptsVariant.Custom ?=> besom.CustomResourceOptions = besom.CustomResourceOptions()
): besom.types.Output[R] =
ctx.readOrRegisterResource[R, A](p"kubernetes:${args.apiVersion}:${args.kind}".map(ResourceType(_)), name, args, opts(using besom.ResourceOptsVariant.Custom))

given factoryOutputOps: {} with
extension (output: besom.types.Output[R])
def urn: besom.types.Output[besom.types.URN] = output.flatMap(_.urn)
def id: besom.types.Output[besom.types.ResourceId] = output.flatMap(_.id)
def apiVersion: besom.types.Output[String] = output.flatMap(_.apiVersion)
def kind: besom.types.Output[String] = output.flatMap(_.kind)
def metadata: besom.types.Output[besom.api.kubernetes.meta.v1.outputs.ObjectMeta] = output.flatMap(_.metadata)
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package besom.api.kubernetes.apiextensions

/** The set of arguments for constructing a CustomResource resource.
*
* NOTE: This type is fairly loose, since other than `apiVersion` and `kind`, there are no fields required across all CRDs.
*/
trait CustomResourceArgsLike:
/** 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.
* @see
* [[https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources Kubernetes API Version]]
* @return
*/
def apiVersion: besom.types.Input[String]

/** 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.
*
* @see
* [[https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds Kubernetes Kinds]]
* @return
*/
def kind: besom.types.Input[String]

/** Standard Kubernetes object metadata
* @see
* [[https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata Kubernetes Metadata]]
* @return
* the object metadata
*/
def metadata: besom.types.Input[scala.Option[besom.api.kubernetes.meta.v1.inputs.ObjectMetaArgs]]
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package besom.api.kubernetes.apiextensions

import besom.util.interpolator.{*, given}
import besom.types.ResourceType

/** CustomResourcePatchPatch represents a resource definition we'd use to patch an instance of a Kubernetes CustomResourceDefinition (CRD).
*
* For example, the CoreOS Prometheus operator exposes a CRD `monitoring.coreos.com/ServiceMonitor` to instantiate this as a Pulumi
* resource, one could call `new CustomResourcePatch`, passing the `ServiceMonitor` resource definition as an argument.
*/
trait CustomResourcePatchLike extends besom.CustomResource:
/** 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.
*
* @see
* [[https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources Kubernetes API Version]]
* @return
*/
def apiVersion: besom.types.Output[String]

/** 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.
*
* @see
* [[https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds Kubernetes Kinds]]
* @return
*/
def kind: besom.types.Output[String]

/** Standard Kubernetes object metadata
*
* @see
* [[https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata Kubernetes Metadata]]
* @return
* the object metadata
*/
def metadata: besom.types.Output[besom.api.kubernetes.meta.v1.outputs.ObjectMeta]
end CustomResourcePatchLike

trait CustomResourcePatchFactory[
R <: besom.api.kubernetes.apiextensions.CustomResourcePatchLike,
A <: besom.api.kubernetes.apiextensions.CustomResourcePatchArgsLike
]:

/** Create a CustomResourcePatch resource with the given unique name, arguments, and options.
*
* @param name
* The unique name of the resource.
* @param args
* The arguments to use to populate this resource's properties.
* @param opts
* A bag of options that control this resource's behavior.
*/
def apply(using ctx: besom.types.Context, dd: besom.types.ResourceDecoder[R], ae: besom.types.ArgsEncoder[A])(
name: besom.util.NonEmptyString,
args: A,
opts: besom.ResourceOptsVariant.Custom ?=> besom.CustomResourceOptions = besom.CustomResourceOptions()
): besom.types.Output[R] =
ctx.readOrRegisterResource[R, A](
p"kubernetes:${args.apiVersion}:${args.kind}Patch".map(ResourceType(_)),
name,
args,
opts(using besom.ResourceOptsVariant.Custom)
)

given factoryOutputOps: {} with
extension (output: besom.types.Output[R])
def urn: besom.types.Output[besom.types.URN] = output.flatMap(_.urn)
def id: besom.types.Output[besom.types.ResourceId] = output.flatMap(_.id)
def apiVersion: besom.types.Output[String] = output.flatMap(_.apiVersion)
def kind: besom.types.Output[String] = output.flatMap(_.kind)
def metadata: besom.types.Output[besom.api.kubernetes.meta.v1.outputs.ObjectMeta] = output.flatMap(_.metadata)
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package besom.api.kubernetes.apiextensions

/** The set of arguments for constructing a CustomResourcePatch resource.
*
* NOTE: This type is fairly loose, since other than `apiVersion` and `kind`, there are no fields required across all CRDs.
*/
trait CustomResourcePatchArgsLike:
/** 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.
* @see
* [[https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources Kubernetes API Version]]
* @return
*/
def apiVersion: besom.types.Input[String]

/** 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.
*
* @see
* [[https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds Kubernetes Kinds]]
* @return
*/
def kind: besom.types.Input[String]

/** Standard Kubernetes object metadata
* @see
* [[https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata Kubernetes Metadata]]
* @return
* the object metadata
*/
def metadata: besom.types.Input[scala.Option[besom.api.kubernetes.meta.v1.inputs.ObjectMetaArgs]]

Loading

0 comments on commit fd8162e

Please sign in to comment.