generated from crossplane/function-template-go
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #83 from phisco/extra-resources
- Loading branch information
Showing
8 changed files
with
340 additions
and
3 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
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,54 @@ | ||
apiVersion: apiextensions.crossplane.io/v1 | ||
kind: Composition | ||
metadata: | ||
name: example-extra-resources | ||
spec: | ||
compositeTypeRef: | ||
apiVersion: example.crossplane.io/v1beta1 | ||
kind: XR | ||
mode: Pipeline | ||
pipeline: | ||
- step: render-templates | ||
functionRef: | ||
name: function-go-templating | ||
input: | ||
apiVersion: gotemplating.fn.crossplane.io/v1beta1 | ||
kind: GoTemplate | ||
source: Inline | ||
inline: | ||
template: | | ||
--- | ||
apiVersion: meta.gotemplating.fn.crossplane.io/v1alpha1 | ||
kind: ExtraResources | ||
requirements: | ||
bucket: | ||
apiVersion: s3.aws.upbound.io/v1beta1 | ||
kind: Bucket | ||
matchName: my-awesome-{{ .observed.composite.resource.spec.environment }}-bucket | ||
{{- with .extraResources }} | ||
{{ $someExtraResources := index . "bucket" }} | ||
{{- range $i, $extraResource := $someExtraResources.items }} | ||
--- | ||
apiVersion: kubernetes.crossplane.io/v1alpha1 | ||
kind: Object | ||
metadata: | ||
annotations: | ||
gotemplating.fn.crossplane.io/composition-resource-name: bucket-configmap-{{ $i }} | ||
spec: | ||
forProvider: | ||
manifest: | ||
apiVersion: v1 | ||
kind: Configmap | ||
metadata: | ||
name: {{ $extraResource.resource.metadata.name }}-bucket | ||
data: | ||
bucket: {{ $extraResource.resource.status.atProvider.id }} | ||
providerConfigRef: | ||
name: "kubernetes" | ||
{{- end }} | ||
{{- end }} | ||
--- | ||
apiVersion: example.crossplane.io/v1beta1 | ||
kind: XR | ||
status: | ||
dummy: cool-status |
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,13 @@ | ||
--- | ||
apiVersion: s3.aws.upbound.io/v1beta1 | ||
kind: Bucket | ||
metadata: | ||
labels: | ||
testing.upbound.io/example-name: bucket-notification | ||
name: my-awesome-dev-bucket | ||
spec: | ||
forProvider: | ||
region: us-west-1 | ||
status: | ||
atProvider: | ||
id: random-bucket-id |
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,6 @@ | ||
apiVersion: pkg.crossplane.io/v1beta1 | ||
kind: Function | ||
metadata: | ||
name: function-go-templating | ||
spec: | ||
package: xpkg.upbound.io/crossplane-contrib/function-go-templating:v0.4.1 |
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,6 @@ | ||
apiVersion: example.crossplane.io/v1beta1 | ||
kind: XR | ||
metadata: | ||
name: example | ||
spec: | ||
environment: dev |
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,43 @@ | ||
package main | ||
|
||
import ( | ||
fnv1beta1 "github.com/crossplane/function-sdk-go/proto/v1beta1" | ||
) | ||
|
||
// ExtraResourcesRequirements defines the requirements for extra resources. | ||
type ExtraResourcesRequirements map[string]ExtraResourcesRequirement | ||
|
||
// ExtraResourcesRequirement defines a single requirement for extra resources. | ||
// Needed to have camelCase keys instead of the snake_case keys as defined | ||
// through json tags by fnv1beta1.ResourceSelector. | ||
type ExtraResourcesRequirement struct { | ||
// APIVersion of the resource. | ||
APIVersion string `json:"apiVersion"` | ||
// Kind of the resource. | ||
Kind string `json:"kind"` | ||
// MatchLabels defines the labels to match the resource, if defined, | ||
// matchName is ignored. | ||
MatchLabels map[string]string `json:"matchLabels,omitempty"` | ||
// MatchName defines the name to match the resource, if MatchLabels is | ||
// empty. | ||
MatchName string `json:"matchName,omitempty"` | ||
} | ||
|
||
// ToResourceSelector converts the ExtraResourcesRequirement to a fnv1beta1.ResourceSelector. | ||
func (e *ExtraResourcesRequirement) ToResourceSelector() *fnv1beta1.ResourceSelector { | ||
out := &fnv1beta1.ResourceSelector{ | ||
ApiVersion: e.APIVersion, | ||
Kind: e.Kind, | ||
} | ||
if e.MatchName == "" { | ||
out.Match = &fnv1beta1.ResourceSelector_MatchLabels{ | ||
MatchLabels: &fnv1beta1.MatchLabels{Labels: e.MatchLabels}, | ||
} | ||
return out | ||
} | ||
|
||
out.Match = &fnv1beta1.ResourceSelector_MatchName{ | ||
MatchName: e.MatchName, | ||
} | ||
return out | ||
} |
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
Oops, something went wrong.