Skip to content

Commit

Permalink
add host crossplane xrd resource
Browse files Browse the repository at this point in the history
  • Loading branch information
metacoma committed May 14, 2024
1 parent 506a9a7 commit 774035c
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 35 deletions.
13 changes: 13 additions & 0 deletions config.k
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,19 @@ Mindwm = {
"trigger-user-broker-to" + delimiter + context_name
}
}
host = {
broker = {
configmap = lambda host_name : str -> str {
host_name + delimiter + "broker-configmap"
}
name = lambda host_name : str -> str {
host_name + delimiter + "broker"
}
}
trigger = lambda host_name : str -> str {
"trigger-host-broker-to" + delimiter + host_name
}
}
}

kafka_cluster_name = "neo4j-cdc"
Expand Down
141 changes: 106 additions & 35 deletions crossplane/xrd_kcl_function.k
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ items = [
}
}
}
# redpanda (kafka topic) for broadcast graph changes to process eventing
# redpanda (kafka topic) for broadcast graph changes to process eventing
{
apiVersion = "kubernetes.crossplane.io/v1alpha2"
kind = "Object"
Expand All @@ -116,7 +116,7 @@ items = [
metadata = {
name = kafkaTopicName
namespace = "${config.kafka.namespace}"
}
}
spec = {
partitions = 1
replicationFactor = 1
Expand Down Expand Up @@ -183,7 +183,7 @@ items = [
volumeMounts = [{
mountPath = "/var/lib/neo4j/plugins"
name = "neo4j-plugins"
}]
}]
workingDir = "/var/lib/neo4j/plugins"
command = [
"curl",
Expand All @@ -201,7 +201,7 @@ items = [
volumeMounts = [{
mountPath = "/var/lib/neo4j/plugins"
name = "neo4j-plugins"
}]
}]
command = [
"curl",
"-Lo"
Expand All @@ -210,7 +210,7 @@ items = [
"https://github.com/neo4j-contrib/neo4j-streams/releases/download/4.1.3/neo4j-streams-4.1.3.jar"
]
}
]
]

}
}
Expand All @@ -226,7 +226,7 @@ items = [
metadata = {
name = contextBroker.configMapName("{{ context_name }}")
namespace = makeContextNamespace("{{ context_name }}")
}
}
data = {
"channel-template-spec" = '''
apiVersion: messaging.knative.dev/v1
Expand All @@ -249,7 +249,7 @@ kind: InMemoryChannel
annotations = {
"eventing.knative.dev/broker.class" = "MTChannelBasedBroker"
}
}
}
spec.config = {
apiVersion = "v1"
kind = "ConfigMap"
Expand All @@ -269,15 +269,15 @@ kind: InMemoryChannel
metadata = {
name = contextBroker.kafkaSourceName("{{ context_name }}")
namespace = makeContextNamespace("{{ context_name }}")
}
}
spec = {
bootstrapServers = [ "${config.kafka.brokerEndpoint}" ]
consumerGroup = "knative-group"
sink.ref = {
apiVersion = "eventing.knative.dev/v1"
kind = "Broker"
name = contextBroker.name("{{ context_name }}")
}
}
topics = [ "{{ kafkaTopicName }}" ]
}

Expand All @@ -294,7 +294,7 @@ kind: InMemoryChannel
metadata = {
name = contextBroker.deadLetterName("{{ context_name }}")
namespace = makeContextNamespace("{{ context_name }}")
}
}
spec.template.spec.containers = [{
image = "${config.knativeBroker.deadLetterImage}"
}]
Expand Down Expand Up @@ -322,7 +322,7 @@ makeUserXR = lambda {
properties.context = {
type = "array"
items.type = "string"
}
}
}, [
{
step = "resources"
Expand Down Expand Up @@ -350,7 +350,7 @@ items = [
metadata = {
name = Mindwm.user.broker.configmap()
namespace = Mindwm.user.namespace("{{ user_name }}")
}
}
data = {
"channel-template-spec" = '''
apiVersion: messaging.knative.dev/v1
Expand All @@ -372,7 +372,7 @@ kind: InMemoryChannel
annotations = {
"eventing.knative.dev/broker.class" = "MTChannelBasedBroker"
}
}
}
spec.config = {
apiVersion = "v1"
kind = "ConfigMap"
Expand All @@ -393,7 +393,7 @@ kind: InMemoryChannel
metadata = {
name = Mindwm.user.deadLetter.name
namespace = Mindwm.user.namespace("{{ user_name }}")
}
}
spec.template.spec.containers = [{
image = "${config.knativeBroker.deadLetterImage}"
}]
Expand All @@ -411,16 +411,16 @@ kind: InMemoryChannel
metadata = {
name = Mindwm.user.contextTrigger("{{ context_name }}")
namespace = Mindwm.user.namespace("{{ user_name }}")
}
}
spec = {
broker = Mindwm.user.broker.name
delivery = {
deadLetterSink.ref = {
apiVersion = "serving.knative.dev/v1"
kind = "Service"
name = Mindwm.user.deadLetter.name
}
}
}
}
filters = [
{
exact.type = "iodocument"
Expand All @@ -434,7 +434,7 @@ kind: InMemoryChannel
}
}
}
}
}
for context_name in context_names
]
""", {
Expand All @@ -456,45 +456,116 @@ makeHostXR = lambda {
}, {
type = "object"
properties.name.type = "string"
properties.username.type = "string"
}, [
{
step = "resources"
functionRef.name = "function-kcl"
input = {
apiVersion = "krm.kcl.dev/v1alpha1"
kind = "KCLRun"
spec.source = template.execute("""host_name = option("params").oxr.spec.name
# TODO (@metacoma) add kcl_util_func to template data in mk function
spec.source = template.execute("""${kcl_util_func}
host_name = option("params").oxr.spec.name
user_name = option("params").oxr.spec.username
items = [
{
apiVersion = "kubernetes.crossplane.io/v1alpha2"
kind = "Object"
metadata.name = "host-configmap-{{ host_name }}"
spec = {
forProvider = {
manifest = {
apiVersion = "v1"
kind = "ConfigMap"
metadata.name = "host-configmap-{{ host_name }}"
metadata.namespace = "default"
data = {
foo = "bar"
}
metadata.name = Mindwm.host.broker.configmap("{{ host_name }}")
spec.forProvider.manifest = {
apiVersion = "v1"
kind = "ConfigMap"
metadata = {
name = Mindwm.host.broker.configmap("{{ host_name }}")
namespace = Mindwm.user.namespace("{{ user_name }}")
labels = {
"eventing.knative.dev/release" = "devel"
}
}
data = {
"channelTemplateSpec" = '''
apiVersion: messaging.knative.dev/v1alpha1
kind: NatsJetStreamChannel
spec:
stream:
config:
additionalSubjects:
- "mindwm.{{ user_name }}.{{ host_name }}.>"
overrideName: amanda
'''
}
}
}
{
apiVersion = "kubernetes.crossplane.io/v1alpha2"
kind = "Object"
metadata.name = Mindwm.host.broker.name("{{ host_name }}")
spec.forProvider.manifest = {
apiVersion = "eventing.knative.dev/v1"
kind = "Broker"
metadata = {
name = Mindwm.host.broker.name("{{ host_name }}")
namespace = Mindwm.user.namespace("{{ user_name }}")
annotations = {
"eventing.knative.dev/broker.class" = "MTChannelBasedBroker"
}
}
spec.config = {
apiVersion = "v1"
kind = "ConfigMap"
name = Mindwm.host.broker.configmap("{{ host_name }}")
}

}
}

{
apiVersion = "kubernetes.crossplane.io/v1alpha2"
kind = "Object"
metadata.name = Mindwm.host.trigger("{{ host_name }}")
spec.forProvider.manifest = {
apiVersion = "eventing.knative.dev/v1"
kind = "Trigger"
metadata = {
name = Mindwm.host.trigger("{{ host_name }}")
namespace = Mindwm.user.namespace("{{ user_name }}")
}
spec = {
broker = Mindwm.host.broker.name("{{ host_name }}")
delivery = {
deadLetterSink.ref = {
apiVersion = "serving.knative.dev/v1"
kind = "Service"
name = Mindwm.user.deadLetter.name
}
}
filters = [
{
exact.type = "iodocument"
}
]
subscriber.ref = {
apiVersion = "eventing.knative.dev/v1"
kind = "Broker"
name = Mindwm.user.broker
namespace = Mindwm.user.namespace("{{ user_name }}")
}
}
}
}
}
]
""", {
user_name = r"${user_name}"
host_name = r"${host_name}"
kafka_cdc_topic_name = r"${kafka.mkContextCdcTopicName($context_name)}"
})
}
}
])
}

manifests.yaml_stream([
makeContextXR()
makeUserXR()
# makeHostXR()
# makeContextXR()
# makeUserXR()
makeHostXR()
])
9 changes: 9 additions & 0 deletions main.k
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,15 @@ mindwm_app = ArgoCdOrder.make({
})
for resource in XrdKclFunction.makeUserXR()
]

[
p.merge(resource, {
metadata.annotations = {
"argocd.argoproj.io/sync-options" = "SkipDryRunOnMissingResource=true"
}
})
for resource in XrdKclFunction.makeHostXR()
]
]

})
Expand Down

0 comments on commit 774035c

Please sign in to comment.