Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(crossplane): split off core libs into separate repository #486

Merged
merged 1 commit into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -851,6 +851,46 @@
"SSH_KEY": "${{ secrets.DEPLOY_KEY }}"
"if": "steps.filter.outputs.workflows == 'true'"
"run": "make libs/crossplane"
"crossplane-core":
"name": "Generate crossplane-core Jsonnet library and docs"
"needs":
- "build"
- "repos"
"runs-on": "ubuntu-latest"
"steps":
- "uses": "actions/checkout@v4"
- "id": "filter"
"uses": "dorny/paths-filter@v3"
"with":
"filters": |
workflows:
- '.github/**'
- 'bin/**'
- 'Dockerfile'
- 'go.mod'
- 'go.sum'
- 'jsonnet/**'
- 'main.go'
- 'Makefile'
- 'pkg/**'
- 'scripts/**'
- 'tf/**'
- 'libs/crossplane-core/**'
- "if": "steps.filter.outputs.workflows == 'true'"
"uses": "actions/download-artifact@v4"
"with":
"name": "docker-artifact"
"path": "artifacts"
- "if": "steps.filter.outputs.workflows == 'true'"
"run": "make load"
- "env":
"DIFF": "true"
"GEN_COMMIT": "${{ github.ref == 'refs/heads/master' && github.repository == 'jsonnet-libs/k8s' }}"
"GIT_COMMITTER_EMAIL": "[email protected]"
"GIT_COMMITTER_NAME": "jsonnet-libs-bot"
"SSH_KEY": "${{ secrets.DEPLOY_KEY }}"
"if": "steps.filter.outputs.workflows == 'true'"
"run": "make libs/crossplane-core"
"datadog-operator":
"name": "Generate datadog-operator Jsonnet library and docs"
"needs":
Expand Down Expand Up @@ -2359,6 +2399,7 @@
- "consul"
- "contour"
- "crossplane"
- "crossplane-core"
- "datadog-operator"
- "eck-operator"
- "edp-keycloak-operator"
Expand Down
30 changes: 30 additions & 0 deletions libs/crossplane-core/config.jsonnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
local config = import 'jsonnet/config.jsonnet';

config.new(
name='crossplane-core',
specs=[
// Crossplane itself
// Release support table: https://github.com/crossplane/crossplane#releases
{
output: 'crossplane/1.17',
prefix: '^io\\.crossplane\\.(pkg|apiextensions)\\..*',
crds: ['https://doc.crds.dev/raw/github.com/crossplane/[email protected]'],
localName: 'crossplane',
patchDir: 'custom/crossplane',
},

// Common functions
{
output: 'function-patch-and-transform/0.7',
prefix: '^io\\.crossplane\\.fn\\.pt\\..*',
crds: ['https://raw.githubusercontent.com/crossplane-contrib/function-patch-and-transform/refs/tags/v0.7.0/package/input/pt.fn.crossplane.io_resources.yaml'],
localName: 'function_patch_and_transform',
},
{
output: 'function-cel-filter/0.1',
prefix: '^io\\.crossplane\\.fn\\.cel\\..*',
crds: ['https://raw.githubusercontent.com/crossplane-contrib/function-cel-filter/refs/tags/v0.1.1/package/input/cel.fn.crossplane.io_filters.yaml'],
localName: 'function_cel_filter',
},
]
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
local d = import 'doc-util/main.libsonnet';

{
apiextensions+: {
v1+: {
xrd: self.compositeResourceDefinition,
compositeResourceDefinition+: {

'#new':: d.fn(help=|||
new returns an instance of CompositeResourceDefinition=

For example: xpostgresqlinstances.example.org

- `kind`: XPostgreSQLInstance
- `plural`: xpostgresqlinstances
- `group`: example.org

A common convention is that the XR (composite resource) are prefixed with 'X'
while claim names are not. This lets app team members think of creating a claim
as (e.g.) 'creating a PostgreSQLInstance'. Use `withClaimNames` to set this.
|||, args=[
d.arg('kind', d.T.string),
d.arg('plural', d.T.string),
d.arg('group', d.T.string),
]),
new(kind, plural, group):
super.new(plural + '.' + group)
+ super.metadata.withAnnotations({
// Tell Tanka to not set metadata.namespace.
'tanka.dev/namespaced': 'false',
})
+ super.spec.withGroup(group)
+ super.spec.names.withKind(kind)
+ super.spec.names.withPlural(plural)
,

'#withClaimNames':: d.fn(help=|||
Sets the ClaimNames attribute.

Example:
- `kind`: PostgreSQLInstance
- `plural`: postgresqlinstances

A common convention is that the XR (composite resource) are prefixed with 'X'
while claim names are not. This lets app team members think of creating a claim
as (e.g.) 'creating a PostgreSQLInstance'.
|||, args=[
d.arg('kind', d.T.string),
d.arg('plural', d.T.string),
]),
withClaimNames(kind, plural):
super.spec.claimNames.withKind(kind)
+ super.spec.claimNames.withPlural(plural),

'#mapVersions':: d.fn(help=|||
Sets the ClaimNames attribute.

Example:
- `kind`: PostgreSQLInstance
- `plural`: postgresqlinstances

A common convention is that the XR (composite resource) are prefixed with 'X'
while claim names are not. This lets app team members think of creating a claim
as (e.g.) 'creating a PostgreSQLInstance'.
|||, args=[
d.arg('kind', d.T.string),
d.arg('plural', d.T.string),
]),
mapVersions(f): {
local versions = super.spec.versions,
spec+: {
versions: std.map(f, versions),
},
},
},
},
},
}
54 changes: 54 additions & 0 deletions libs/crossplane-core/custom/crossplane/composition.libsonnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
local d = import 'doc-util/main.libsonnet';

{
apiextensions+: {
v1+: {
composition+: {
'#fromXRD':: d.fn(help=|||
Create a Composition based on an XRD.

Attributes:
- `name` of the composition
- `namespace` where connectionDetails are propagated too, commonly the the
management namespace (ie. crossplane)
- `provider` of the resources in this composition
- `xrdRef` XRD object with which this composition is compatible
- `xrdVersion` Version of XRD object with which this composition is compatible
|||, args=[
d.arg('name', d.T.string),
d.arg('namespace', d.T.string),
d.arg('provider', d.T.string),
d.arg('xrdRef', d.T.object),
d.arg('xrdVersion', d.T.string),
]),
fromXRD(name, namespace, provider, xrdRef, xrdVersion):
super.new(name)
+ super.metadata.withAnnotations({
// Tell Tanka to not set metadata.namespace.
'tanka.dev/namespaced': 'false',
})
+ super.metadata.withLabels({
// An optional convention is to include a label of the XRD. This allows easy
// discovery of compatible Compositions.
'crossplane.io/xrd': xrdRef.metadata.name,
// Another optional convention is to include a label of the (most common)
// provider for the resource(s) in this composition. This label can be used in
// 'compositionSelector' in an XR or Claim.
provider: provider,
})

// Each Composition must declare that it is compatible with a particular type of
// Composite Resource using its 'compositeTypeRef' field. The referenced
// version must be marked 'referenceable' in the XRD that defines the XR.
+ super.spec.compositeTypeRef.withApiVersion(xrdRef.spec.group + '/' + xrdVersion)
+ super.spec.compositeTypeRef.withKind(xrdRef.spec.names.kind)


// When an XR is created in response to a claim Crossplane needs to know where it
// should create the XR's connection secret. This is configured using the
// 'writeConnectionSecretsToNamespace' field.
+ super.spec.withWriteConnectionSecretsToNamespace(namespace),
},
},
},
}
Loading
Loading