-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(crossplane): extend crossplane lib with various helper functions (…
- Loading branch information
Showing
4 changed files
with
514 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,18 +8,21 @@ config.new( | |
prefix: '^io\\.crossplane\\.(pkg|apiextensions)\\..*', | ||
crds: ['https://doc.crds.dev/raw/github.com/crossplane/[email protected]'], | ||
localName: 'crossplane', | ||
patchDir: 'custom/crossplane', | ||
}, | ||
{ | ||
output: 'crossplane/1.6', | ||
prefix: '^io\\.crossplane\\.(pkg|apiextensions)\\..*', | ||
crds: ['https://doc.crds.dev/raw/github.com/crossplane/[email protected]'], | ||
localName: 'crossplane', | ||
patchDir: 'custom/crossplane', | ||
}, | ||
{ | ||
output: 'crossplane/1.5', | ||
prefix: '^io\\.crossplane\\.(pkg|apiextensions)\\..*', | ||
crds: ['https://doc.crds.dev/raw/github.com/crossplane/[email protected]'], | ||
localName: 'crossplane', | ||
patchDir: 'custom/crossplane', | ||
}, | ||
{ | ||
output: 'provider-aws/0.24', | ||
|
78 changes: 78 additions & 0 deletions
78
libs/crossplane/custom/crossplane/compositeResourceDefinition.libsonnet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
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('resource', d.T.object), | ||
]), | ||
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), | ||
}, | ||
}, | ||
}, | ||
} |
Oops, something went wrong.