From fe64d757306e95dc42f4605339450180a1a8f095 Mon Sep 17 00:00:00 2001 From: Knut-Erik Johnsen Date: Tue, 25 Jun 2024 00:13:46 +0200 Subject: [PATCH 1/3] Upgrade to 1.16, adding the credentialmap and observedgeneration to the crossplane crds (#6) Signed-off-by: Knut-Erik Johnsen --- ...plane.io_compositeresourcedefinitions.yaml | 16 ++- ...ns.crossplane.io_compositionrevisions.yaml | 126 ++++++++++++++++-- ...extensions.crossplane.io_compositions.yaml | 59 +++++++- ...ions.crossplane.io_environmentconfigs.yaml | 9 +- .../apiextensions.crossplane.io_usages.yaml | 19 ++- .../src/main/resources/kubernetes/fetch.sh | 2 +- .../base/CrossplaneCompositeFunctionBase.java | 3 +- .../base/CrossplaneFunctionRequest.java | 9 +- .../src/main/proto/fetch.sh | 2 +- .../src/main/proto/run_function.proto | 25 ++++ 10 files changed, 237 insertions(+), 33 deletions(-) diff --git a/crossplane-crd-model/src/main/resources/kubernetes/apiextensions.crossplane.io_compositeresourcedefinitions.yaml b/crossplane-crd-model/src/main/resources/kubernetes/apiextensions.crossplane.io_compositeresourcedefinitions.yaml index 602690a..99c5074 100644 --- a/crossplane-crd-model/src/main/resources/kubernetes/apiextensions.crossplane.io_compositeresourcedefinitions.yaml +++ b/crossplane-crd-model/src/main/resources/kubernetes/apiextensions.crossplane.io_compositeresourcedefinitions.yaml @@ -32,9 +32,12 @@ spec: schema: openAPIV3Schema: description: |- - A CompositeResourceDefinition defines a new kind of composite infrastructure - resource. The new resource is composed of other composite or managed - infrastructure resources. + A CompositeResourceDefinition defines the schema for a new custom Kubernetes + API. + + + Read the Crossplane documentation for + [more information about CustomResourceDefinitions](https://docs.crossplane.io/latest/concepts/composite-resource-definitions). properties: apiVersion: description: |- @@ -480,6 +483,13 @@ spec: A Message containing details about this condition's last transition from one status to another, if any. type: string + observedGeneration: + description: |- + ObservedGeneration represents the .metadata.generation that the condition was set based upon. + For instance, if .metadata.generation is currently 12, but the .status.conditions[x].observedGeneration is 9, the condition is out of date + with respect to the current state of the instance. + format: int64 + type: integer reason: description: A Reason for this condition's last transition from one status to another. diff --git a/crossplane-crd-model/src/main/resources/kubernetes/apiextensions.crossplane.io_compositionrevisions.yaml b/crossplane-crd-model/src/main/resources/kubernetes/apiextensions.crossplane.io_compositionrevisions.yaml index 93f4dcb..3c4b7db 100644 --- a/crossplane-crd-model/src/main/resources/kubernetes/apiextensions.crossplane.io_compositionrevisions.yaml +++ b/crossplane-crd-model/src/main/resources/kubernetes/apiextensions.crossplane.io_compositionrevisions.yaml @@ -34,8 +34,12 @@ spec: schema: openAPIV3Schema: description: |- - A CompositionRevision represents a revision in time of a Composition. - Revisions are created by Crossplane; they should be treated as immutable. + A CompositionRevision represents a revision of a Composition. Crossplane + creates new revisions when there are changes to the Composition. + + + Crossplane creates and manages CompositionRevisions. Don't directly edit + CompositionRevisions. properties: apiVersion: description: |- @@ -283,7 +287,7 @@ spec: type: string mergeOptions: description: MergeOptions Specifies merge options on - a field path + a field path. properties: appendSlice: description: Specifies that already existing elements @@ -697,7 +701,7 @@ spec: type: string mergeOptions: description: MergeOptions Specifies merge options - on a field path + on a field path. properties: appendSlice: description: Specifies that already existing elements @@ -987,6 +991,46 @@ spec: items: description: A PipelineStep in a Composition Function pipeline. properties: + credentials: + description: Credentials are optional credentials that the Composition + Function needs. + items: + description: |- + FunctionCredentials are optional credentials that a Composition Function + needs to run. + properties: + name: + description: Name of this set of credentials. + type: string + secretRef: + description: |- + A SecretRef is a reference to a secret containing credentials that should + be supplied to the function. + properties: + name: + description: Name of the secret. + type: string + namespace: + description: Namespace of the secret. + type: string + required: + - name + - namespace + type: object + source: + description: Source of the function credentials. + enum: + - None + - Secret + type: string + required: + - name + - source + type: object + type: array + x-kubernetes-list-map-keys: + - name + x-kubernetes-list-type: map functionRef: description: |- FunctionRef is a reference to the Composition Function this step should @@ -1195,7 +1239,7 @@ spec: type: string mergeOptions: description: MergeOptions Specifies merge options - on a field path + on a field path. properties: appendSlice: description: Specifies that already existing elements @@ -1477,7 +1521,7 @@ spec: items: description: |- ReadinessCheck is used to indicate how to tell whether a resource is ready - for consumption + for consumption. properties: fieldPath: description: FieldPath shows the path of the field whose @@ -1570,6 +1614,13 @@ spec: A Message containing details about this condition's last transition from one status to another, if any. type: string + observedGeneration: + description: |- + ObservedGeneration represents the .metadata.generation that the condition was set based upon. + For instance, if .metadata.generation is currently 12, but the .status.conditions[x].observedGeneration is 9, the condition is out of date + with respect to the current state of the instance. + format: int64 + type: integer reason: description: A Reason for this condition's last transition from one status to another. @@ -1616,8 +1667,12 @@ spec: schema: openAPIV3Schema: description: |- - A CompositionRevision represents a revision in time of a Composition. - Revisions are created by Crossplane; they should be treated as immutable. + A CompositionRevision represents a revision of a Composition. Crossplane + creates new revisions when there are changes to the Composition. + + + Crossplane creates and manages CompositionRevisions. Don't directly edit + CompositionRevisions. properties: apiVersion: description: |- @@ -1865,7 +1920,7 @@ spec: type: string mergeOptions: description: MergeOptions Specifies merge options on - a field path + a field path. properties: appendSlice: description: Specifies that already existing elements @@ -2279,7 +2334,7 @@ spec: type: string mergeOptions: description: MergeOptions Specifies merge options - on a field path + on a field path. properties: appendSlice: description: Specifies that already existing elements @@ -2569,6 +2624,46 @@ spec: items: description: A PipelineStep in a Composition Function pipeline. properties: + credentials: + description: Credentials are optional credentials that the Composition + Function needs. + items: + description: |- + FunctionCredentials are optional credentials that a Composition Function + needs to run. + properties: + name: + description: Name of this set of credentials. + type: string + secretRef: + description: |- + A SecretRef is a reference to a secret containing credentials that should + be supplied to the function. + properties: + name: + description: Name of the secret. + type: string + namespace: + description: Namespace of the secret. + type: string + required: + - name + - namespace + type: object + source: + description: Source of the function credentials. + enum: + - None + - Secret + type: string + required: + - name + - source + type: object + type: array + x-kubernetes-list-map-keys: + - name + x-kubernetes-list-type: map functionRef: description: |- FunctionRef is a reference to the Composition Function this step should @@ -2777,7 +2872,7 @@ spec: type: string mergeOptions: description: MergeOptions Specifies merge options - on a field path + on a field path. properties: appendSlice: description: Specifies that already existing elements @@ -3059,7 +3154,7 @@ spec: items: description: |- ReadinessCheck is used to indicate how to tell whether a resource is ready - for consumption + for consumption. properties: fieldPath: description: FieldPath shows the path of the field whose @@ -3152,6 +3247,13 @@ spec: A Message containing details about this condition's last transition from one status to another, if any. type: string + observedGeneration: + description: |- + ObservedGeneration represents the .metadata.generation that the condition was set based upon. + For instance, if .metadata.generation is currently 12, but the .status.conditions[x].observedGeneration is 9, the condition is out of date + with respect to the current state of the instance. + format: int64 + type: integer reason: description: A Reason for this condition's last transition from one status to another. diff --git a/crossplane-crd-model/src/main/resources/kubernetes/apiextensions.crossplane.io_compositions.yaml b/crossplane-crd-model/src/main/resources/kubernetes/apiextensions.crossplane.io_compositions.yaml index cb1d489..61e6d4c 100644 --- a/crossplane-crd-model/src/main/resources/kubernetes/apiextensions.crossplane.io_compositions.yaml +++ b/crossplane-crd-model/src/main/resources/kubernetes/apiextensions.crossplane.io_compositions.yaml @@ -30,7 +30,13 @@ spec: name: v1 schema: openAPIV3Schema: - description: A Composition specifies how a composite resource should be composed. + description: |- + A Composition defines a collection of managed resources or functions that + Crossplane uses to create and manage new composite resources. + + + Read the Crossplane documentation for + [more information about Compositions](https://docs.crossplane.io/latest/concepts/compositions). properties: apiVersion: description: |- @@ -276,7 +282,7 @@ spec: type: string mergeOptions: description: MergeOptions Specifies merge options on - a field path + a field path. properties: appendSlice: description: Specifies that already existing elements @@ -690,7 +696,7 @@ spec: type: string mergeOptions: description: MergeOptions Specifies merge options - on a field path + on a field path. properties: appendSlice: description: Specifies that already existing elements @@ -980,6 +986,46 @@ spec: items: description: A PipelineStep in a Composition Function pipeline. properties: + credentials: + description: Credentials are optional credentials that the Composition + Function needs. + items: + description: |- + FunctionCredentials are optional credentials that a Composition Function + needs to run. + properties: + name: + description: Name of this set of credentials. + type: string + secretRef: + description: |- + A SecretRef is a reference to a secret containing credentials that should + be supplied to the function. + properties: + name: + description: Name of the secret. + type: string + namespace: + description: Namespace of the secret. + type: string + required: + - name + - namespace + type: object + source: + description: Source of the function credentials. + enum: + - None + - Secret + type: string + required: + - name + - source + type: object + type: array + x-kubernetes-list-map-keys: + - name + x-kubernetes-list-type: map functionRef: description: |- FunctionRef is a reference to the Composition Function this step should @@ -1007,6 +1053,9 @@ spec: - step type: object type: array + x-kubernetes-list-map-keys: + - step + x-kubernetes-list-type: map publishConnectionDetailsWithStoreConfigRef: default: name: default @@ -1188,7 +1237,7 @@ spec: type: string mergeOptions: description: MergeOptions Specifies merge options - on a field path + on a field path. properties: appendSlice: description: Specifies that already existing elements @@ -1470,7 +1519,7 @@ spec: items: description: |- ReadinessCheck is used to indicate how to tell whether a resource is ready - for consumption + for consumption. properties: fieldPath: description: FieldPath shows the path of the field whose diff --git a/crossplane-crd-model/src/main/resources/kubernetes/apiextensions.crossplane.io_environmentconfigs.yaml b/crossplane-crd-model/src/main/resources/kubernetes/apiextensions.crossplane.io_environmentconfigs.yaml index 9a703e2..1d80d90 100644 --- a/crossplane-crd-model/src/main/resources/kubernetes/apiextensions.crossplane.io_environmentconfigs.yaml +++ b/crossplane-crd-model/src/main/resources/kubernetes/apiextensions.crossplane.io_environmentconfigs.yaml @@ -24,8 +24,13 @@ spec: name: v1alpha1 schema: openAPIV3Schema: - description: A EnvironmentConfig contains a set of arbitrary, unstructured - values. + description: |- + An EnvironmentConfig contains user-defined unstructured values for + use in a Composition. + + + Read the Crossplane documentation for + [more information about EnvironmentConfigs](https://docs.crossplane.io/latest/concepts/environment-configs). properties: apiVersion: description: |- diff --git a/crossplane-crd-model/src/main/resources/kubernetes/apiextensions.crossplane.io_usages.yaml b/crossplane-crd-model/src/main/resources/kubernetes/apiextensions.crossplane.io_usages.yaml index e05a9b4..cc8f7e5 100644 --- a/crossplane-crd-model/src/main/resources/kubernetes/apiextensions.crossplane.io_usages.yaml +++ b/crossplane-crd-model/src/main/resources/kubernetes/apiextensions.crossplane.io_usages.yaml @@ -28,8 +28,16 @@ spec: name: v1alpha1 schema: openAPIV3Schema: - description: A Usage defines a deletion blocking relationship between two - resources. + description: |- + A Usage defines a deletion blocking relationship between two resources. + + + Usages prevent accidental deletion of a single resource or deletion of + resources with dependent resources. + + + Read the Crossplane documentation for + [more information about Compositions](https://docs.crossplane.io/latest/concepts/usages). properties: apiVersion: description: |- @@ -168,6 +176,13 @@ spec: A Message containing details about this condition's last transition from one status to another, if any. type: string + observedGeneration: + description: |- + ObservedGeneration represents the .metadata.generation that the condition was set based upon. + For instance, if .metadata.generation is currently 12, but the .status.conditions[x].observedGeneration is 9, the condition is out of date + with respect to the current state of the instance. + format: int64 + type: integer reason: description: A Reason for this condition's last transition from one status to another. diff --git a/crossplane-crd-model/src/main/resources/kubernetes/fetch.sh b/crossplane-crd-model/src/main/resources/kubernetes/fetch.sh index 516825e..0c3588a 100755 --- a/crossplane-crd-model/src/main/resources/kubernetes/fetch.sh +++ b/crossplane-crd-model/src/main/resources/kubernetes/fetch.sh @@ -1,6 +1,6 @@ #!/bin/bash -release="release-1.15" +release="release-1.16" apiextensions=$(gh api --jq '.[].name' "/repos/crossplane/crossplane/contents/cluster/crds?ref=${release}" | grep apiextensions) diff --git a/crossplane-function-base/src/main/java/io/crossplane/compositefunctions/base/CrossplaneCompositeFunctionBase.java b/crossplane-function-base/src/main/java/io/crossplane/compositefunctions/base/CrossplaneCompositeFunctionBase.java index e18d3b9..926a4e2 100644 --- a/crossplane-function-base/src/main/java/io/crossplane/compositefunctions/base/CrossplaneCompositeFunctionBase.java +++ b/crossplane-function-base/src/main/java/io/crossplane/compositefunctions/base/CrossplaneCompositeFunctionBase.java @@ -33,9 +33,8 @@ public abstract class CrossplaneCompositeFunctionBase extends FunctionRunnerServ desiredBuilder.putAllResources(desired.getResourcesMap()); CrossplaneFunctionRequest crossplaneFunctionRequest = new CrossplaneFunctionRequest(request.getObserved(), - request.getExtraResourcesMap(), request.getDesired()); + request.getExtraResourcesMap(), request.getCredentialsMap(), request.getDesired()); - // request.getCredentialsMap(), logger.debug("Calling method with implemented logic"); CrossplaneFunctionResponse crossplaneFunctionResponse = runFunction(crossplaneFunctionRequest); diff --git a/crossplane-function-base/src/main/java/io/crossplane/compositefunctions/base/CrossplaneFunctionRequest.java b/crossplane-function-base/src/main/java/io/crossplane/compositefunctions/base/CrossplaneFunctionRequest.java index 7babdbb..db2dcf7 100644 --- a/crossplane-function-base/src/main/java/io/crossplane/compositefunctions/base/CrossplaneFunctionRequest.java +++ b/crossplane-function-base/src/main/java/io/crossplane/compositefunctions/base/CrossplaneFunctionRequest.java @@ -1,5 +1,6 @@ package io.crossplane.compositefunctions.base; +import io.crossplane.compositefunctions.protobuf.Credentials; import io.crossplane.compositefunctions.protobuf.Resources; import io.crossplane.compositefunctions.protobuf.State; @@ -9,12 +10,10 @@ import java.util.Map; * Holder for the request from crossplane * @param observedState The observedstate of the crossplane resources * @param extraResourcesMap A map of any extra resources requested + * @param credentialsMap A map of credentials sent as input * @param desiredState The sum of previously called functions state. To override, create a new resource with the same name in the response */ -public record CrossplaneFunctionRequest(State observedState, Map extraResourcesMap, State desiredState) { +public record CrossplaneFunctionRequest(State observedState, Map extraResourcesMap, + Map credentialsMap, State desiredState) { - // * - // * @param credentialsMap A map of credentials sent as input - // - // Map credentialsMap } diff --git a/crossplane-protobuf-model/src/main/proto/fetch.sh b/crossplane-protobuf-model/src/main/proto/fetch.sh index c8fc0fc..78b5292 100755 --- a/crossplane-protobuf-model/src/main/proto/fetch.sh +++ b/crossplane-protobuf-model/src/main/proto/fetch.sh @@ -1,6 +1,6 @@ #!/bin/bash -release="release-1.15" +release="release-1.16" file="run_function.proto" gh api -H "Accept: application/vnd.github.raw+json" "/repos/crossplane/crossplane/contents/apis/apiextensions/fn/proto/v1beta1/${file}?ref=${release}" > $file diff --git a/crossplane-protobuf-model/src/main/proto/run_function.proto b/crossplane-protobuf-model/src/main/proto/run_function.proto index 7dc0df5..7db077e 100644 --- a/crossplane-protobuf-model/src/main/proto/run_function.proto +++ b/crossplane-protobuf-model/src/main/proto/run_function.proto @@ -70,6 +70,24 @@ message RunFunctionRequest { // did not exist, Crossplane sets the map key to an empty Resources message to // indicate that it attempted to satisfy the request. map extra_resources = 6; + + // Optional credentials that this Function may use to communicate with an + // external system. + map credentials = 7; +} + +// Credentials that a Function may use to communicate with an external system. +message Credentials { + // Source of the credentials. + oneof source { + // Credential data loaded by Crossplane, for example from a Secret. + CredentialData credential_data = 1; + } +} + +// CredentialData loaded by Crossplane, for example from a Secret. +message CredentialData { + map data = 1; } // Resources represents the state of several Crossplane resources. @@ -123,11 +141,18 @@ message Requirements { // ResourceSelector selects a group of resources, either by name or by label. message ResourceSelector { + // API version of resources to select. string api_version = 1; + + // Kind of resources to select. string kind = 2; + // Resources to match. oneof match { + // Match the resource with this name. string match_name = 3; + + // Match all resources with these labels. MatchLabels match_labels = 4; } } From 49b77de9fbe0d31ca62b1e920d39d696e3528924 Mon Sep 17 00:00:00 2001 From: Knut-Erik Johnsen Date: Tue, 25 Jun 2024 21:48:31 +0200 Subject: [PATCH 2/3] Removed extra = in newVersion. Added target to release action to use the correct branch (#7) (#8) (#9) Signed-off-by: Knut-Erik Johnsen --- .github/workflows/maven-release.yaml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/maven-release.yaml b/.github/workflows/maven-release.yaml index b7dbd09..6082681 100644 --- a/.github/workflows/maven-release.yaml +++ b/.github/workflows/maven-release.yaml @@ -26,7 +26,7 @@ jobs: gpg-private-key: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }} # Value of the GPG private key to import gpg-passphrase: MAVEN_GPG_PASSPHRASE # env variable for GPG private key passphrase - name: Set the revision property - run: mvn versions:set-property -Dproperty=revision "-DnewVersion==${{ github.event.inputs.releaseversion }}" -DgenerateBackupPoms=false + run: mvn versions:set-property -Dproperty=revision "-DnewVersion=${{ github.event.inputs.releaseversion }}" -DgenerateBackupPoms=false - name: Build with Maven run: mvn -B deploy --file pom.xml -Pdeploy env: @@ -40,5 +40,6 @@ jobs: run: | gh release create "$tag" \ --repo="$GITHUB_REPOSITORY" \ - --title="${tag#v}" \ - --generate-notes \ No newline at end of file + --title="v${tag#v}" \ + --generate-notes \ + --target "$GITHUB_SHA" \ No newline at end of file From 7c12a0c8ed52acf31e0f7c28ac94b5bc2811c3fc Mon Sep 17 00:00:00 2001 From: Knut-Erik Johnsen Date: Wed, 26 Jun 2024 11:50:56 +0200 Subject: [PATCH 3/3] Release/1.15 (#13) * Removed extra = in newVersion. Added target to release action to use the correct branch (#7) (#8) Signed-off-by: Knut-Erik Johnsen * Release/1.14 (#12) * Removed extra = in newVersion. Added target to release action to use the correct branch (#7) Signed-off-by: Knut-Erik Johnsen * Feature/update workflows (#11) * Removed extra = in newVersion. Added target to release action to use the correct branch Signed-off-by: Knut-Erik Johnsen * Downgraded grpc to same version as the used springboot starter. Added javadoc. Removed componentscan since it's bad practie Signed-off-by: Knut-Erik Johnsen --------- Signed-off-by: Knut-Erik Johnsen --------- Signed-off-by: Knut-Erik Johnsen --------- Signed-off-by: Knut-Erik Johnsen --- .../CrossplaneServiceConfiguration.java | 41 +++++++++- .../CrossplaneExtraResourcesService.java | 11 ++- .../CrossplaneObservableService.java | 13 +++- .../conversion/CrossplaneResourceService.java | 12 ++- .../CrossplaneUnexpectedItemsException.java | 12 +++ .../CrossplaneUnmarshallException.java | 12 +++ .../CrossplaneCompositeResourceMixin.java | 4 + .../CrossplaneCompositeResourceService.java | 74 +++++++++++-------- ...ava => CrossplaneJsonSchemaGenerator.java} | 20 ++++- .../CrossplaneMetadataBuilder.java | 35 ++++++++- pom.xml | 41 +--------- 11 files changed, 195 insertions(+), 80 deletions(-) rename crossplane-function-springboot-starter/src/main/java/io/crossplane/compositefunctions/starter/registration/{CrossplanJsonSchemaGenerator.java => CrossplaneJsonSchemaGenerator.java} (86%) diff --git a/crossplane-function-springboot-starter/src/main/java/io/crossplane/compositefunctions/starter/config/CrossplaneServiceConfiguration.java b/crossplane-function-springboot-starter/src/main/java/io/crossplane/compositefunctions/starter/config/CrossplaneServiceConfiguration.java index dcba8b8..bc1cba7 100644 --- a/crossplane-function-springboot-starter/src/main/java/io/crossplane/compositefunctions/starter/config/CrossplaneServiceConfiguration.java +++ b/crossplane-function-springboot-starter/src/main/java/io/crossplane/compositefunctions/starter/config/CrossplaneServiceConfiguration.java @@ -1,9 +1,48 @@ package io.crossplane.compositefunctions.starter.config; +import io.crossplane.compositefunctions.starter.conversion.CrossplaneExtraResourcesService; +import io.crossplane.compositefunctions.starter.conversion.CrossplaneObservableService; +import io.crossplane.compositefunctions.starter.conversion.CrossplaneResourceService; +import org.checkerframework.checker.units.qual.C; import org.springframework.boot.autoconfigure.AutoConfiguration; +import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; +/** + * Autoconfiguration for the crossplane services. + */ @AutoConfiguration -@ComponentScan(basePackages = {"io.crossplane.compositefunctions.starter.conversion"}) public class CrossplaneServiceConfiguration { + + + /** + * Set up services for working with extra resources + * @return the crossplaneExtraResourcesService + * @since 1.15 + */ + @Bean + public CrossplaneExtraResourcesService crossplaneExtraResourcesService() { + return new CrossplaneExtraResourcesService(); + } + + /** + * Set up services for working with observed resources + * @return the crossplaneObservableService + * @since 1.14 + */ + @Bean + public CrossplaneObservableService crossplaneObservableService() { + return new CrossplaneObservableService(); + } + + /** + * Set up services for working with default resources + * @return the crossplaneResourceService + * @since 1.15 + */ + @Bean + public CrossplaneResourceService crossplaneResourceService() { + return new CrossplaneResourceService(); + } + } diff --git a/crossplane-function-springboot-starter/src/main/java/io/crossplane/compositefunctions/starter/conversion/CrossplaneExtraResourcesService.java b/crossplane-function-springboot-starter/src/main/java/io/crossplane/compositefunctions/starter/conversion/CrossplaneExtraResourcesService.java index 233d3f7..13941d8 100644 --- a/crossplane-function-springboot-starter/src/main/java/io/crossplane/compositefunctions/starter/conversion/CrossplaneExtraResourcesService.java +++ b/crossplane-function-springboot-starter/src/main/java/io/crossplane/compositefunctions/starter/conversion/CrossplaneExtraResourcesService.java @@ -10,15 +10,20 @@ import io.fabric8.kubernetes.api.model.HasMetadata; import io.fabric8.kubernetes.client.utils.Serialization; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.stereotype.Component; import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Optional; - -@Component +/** + * Class that helps with the extra resources map and also to create ResourceSelector in order to get extra resources + * to the function + * + * Commented out in 1.14 + * + * @since 1.15 + */ public class CrossplaneExtraResourcesService { private static final Logger logger = LoggerFactory.getLogger(CrossplaneExtraResourcesService.class); diff --git a/crossplane-function-springboot-starter/src/main/java/io/crossplane/compositefunctions/starter/conversion/CrossplaneObservableService.java b/crossplane-function-springboot-starter/src/main/java/io/crossplane/compositefunctions/starter/conversion/CrossplaneObservableService.java index c1850d5..266357b 100644 --- a/crossplane-function-springboot-starter/src/main/java/io/crossplane/compositefunctions/starter/conversion/CrossplaneObservableService.java +++ b/crossplane-function-springboot-starter/src/main/java/io/crossplane/compositefunctions/starter/conversion/CrossplaneObservableService.java @@ -8,16 +8,25 @@ import io.crossplane.compositefunctions.starter.exception.CrossplaneUnmarshallEx import io.fabric8.kubernetes.client.utils.Serialization; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.stereotype.Component; import java.util.Optional; -@Component +/** + * Class with helper methods for observable resources. + */ public class CrossplaneObservableService { private static final Logger logger = LoggerFactory.getLogger(CrossplaneObservableService.class); private final JsonFormat.Printer printer = JsonFormat.printer(); + /** + * Retrieve a resource from the observedstate and convert in into class T + * @param resourceName The resource name to find in the observed state + * @param observedState The observed state from the crossplane input + * @param clazz The class/type to create + * @return An instance of class T from the observed state + * @param The class/type to create + */ public Optional getObservableResource(String resourceName, State observedState, Class clazz) { Resource observedResource = observedState.getResourcesOrDefault(resourceName, null); Optional result = Optional.empty(); diff --git a/crossplane-function-springboot-starter/src/main/java/io/crossplane/compositefunctions/starter/conversion/CrossplaneResourceService.java b/crossplane-function-springboot-starter/src/main/java/io/crossplane/compositefunctions/starter/conversion/CrossplaneResourceService.java index 12a1a57..7e2ac50 100644 --- a/crossplane-function-springboot-starter/src/main/java/io/crossplane/compositefunctions/starter/conversion/CrossplaneResourceService.java +++ b/crossplane-function-springboot-starter/src/main/java/io/crossplane/compositefunctions/starter/conversion/CrossplaneResourceService.java @@ -4,15 +4,23 @@ import com.google.protobuf.util.JsonFormat; import io.crossplane.compositefunctions.protobuf.State; import io.crossplane.compositefunctions.starter.exception.CrossplaneUnmarshallException; import io.fabric8.kubernetes.client.utils.Serialization; -import org.springframework.stereotype.Component; import java.util.Optional; -@Component +/** + * Class with helper methods for default resources. + */ public class CrossplaneResourceService { final JsonFormat.Printer printer = JsonFormat.printer(); + /** + * Converts the incoming Composite to instance of class T + * @param observedState The observed state from the crossplane input + * @param clazz The class/type to create + * @return An instance of class T from the observed state + * @param The class/type to create + */ public Optional getResource(State observedState, Class clazz) { try { String resource = printer.print(observedState.getComposite().getResource()); diff --git a/crossplane-function-springboot-starter/src/main/java/io/crossplane/compositefunctions/starter/exception/CrossplaneUnexpectedItemsException.java b/crossplane-function-springboot-starter/src/main/java/io/crossplane/compositefunctions/starter/exception/CrossplaneUnexpectedItemsException.java index 1e87c1d..e0bbbdf 100644 --- a/crossplane-function-springboot-starter/src/main/java/io/crossplane/compositefunctions/starter/exception/CrossplaneUnexpectedItemsException.java +++ b/crossplane-function-springboot-starter/src/main/java/io/crossplane/compositefunctions/starter/exception/CrossplaneUnexpectedItemsException.java @@ -1,11 +1,23 @@ package io.crossplane.compositefunctions.starter.exception; +/** + * Exception for unexpected items encountered when converting + */ public class CrossplaneUnexpectedItemsException extends RuntimeException { + /** + * Constructor with message + * @param message The exception message + */ public CrossplaneUnexpectedItemsException(String message) { super(message); } + /** + * Constructor with message and cause + * @param message The exception message + * @param cause The throwable that caused the exception + */ public CrossplaneUnexpectedItemsException(String message, Throwable cause) { super(message, cause); } diff --git a/crossplane-function-springboot-starter/src/main/java/io/crossplane/compositefunctions/starter/exception/CrossplaneUnmarshallException.java b/crossplane-function-springboot-starter/src/main/java/io/crossplane/compositefunctions/starter/exception/CrossplaneUnmarshallException.java index c6b1b93..f6a8645 100644 --- a/crossplane-function-springboot-starter/src/main/java/io/crossplane/compositefunctions/starter/exception/CrossplaneUnmarshallException.java +++ b/crossplane-function-springboot-starter/src/main/java/io/crossplane/compositefunctions/starter/exception/CrossplaneUnmarshallException.java @@ -1,11 +1,23 @@ package io.crossplane.compositefunctions.starter.exception; +/** + * Exception for errors when unmarhsalling + */ public class CrossplaneUnmarshallException extends RuntimeException { + /** + * Constructor with message + * @param message The exception message + */ public CrossplaneUnmarshallException(String message) { super(message); } + /** + * Constructor with message and cause + * @param message The exception message + * @param cause The throwable that caused the exception + */ public CrossplaneUnmarshallException(String message, Throwable cause) { super(message, cause); } diff --git a/crossplane-function-springboot-starter/src/main/java/io/crossplane/compositefunctions/starter/registration/CrossplaneCompositeResourceMixin.java b/crossplane-function-springboot-starter/src/main/java/io/crossplane/compositefunctions/starter/registration/CrossplaneCompositeResourceMixin.java index fce63ab..6aaeaf8 100644 --- a/crossplane-function-springboot-starter/src/main/java/io/crossplane/compositefunctions/starter/registration/CrossplaneCompositeResourceMixin.java +++ b/crossplane-function-springboot-starter/src/main/java/io/crossplane/compositefunctions/starter/registration/CrossplaneCompositeResourceMixin.java @@ -3,6 +3,10 @@ package io.crossplane.compositefunctions.starter.registration; import com.fasterxml.jackson.annotation.JsonIgnore; import io.fabric8.kubernetes.api.model.ObjectMeta; +/** + * Class to aid in setting up autoregistration. Used to ignore the default + * fields when creating the openapiv3schema + */ public abstract class CrossplaneCompositeResourceMixin { @JsonIgnore diff --git a/crossplane-function-springboot-starter/src/main/java/io/crossplane/compositefunctions/starter/registration/CrossplaneCompositeResourceService.java b/crossplane-function-springboot-starter/src/main/java/io/crossplane/compositefunctions/starter/registration/CrossplaneCompositeResourceService.java index c57c71b..f5d1528 100644 --- a/crossplane-function-springboot-starter/src/main/java/io/crossplane/compositefunctions/starter/registration/CrossplaneCompositeResourceService.java +++ b/crossplane-function-springboot-starter/src/main/java/io/crossplane/compositefunctions/starter/registration/CrossplaneCompositeResourceService.java @@ -19,22 +19,33 @@ import io.fabric8.kubernetes.client.dsl.Resource; import java.util.ArrayList; import java.util.List; -import static io.crossplane.compositefunctions.starter.registration.CrossplanJsonSchemaGenerator.getOpenAPIV3Schema; +import static io.crossplane.compositefunctions.starter.registration.CrossplaneJsonSchemaGenerator.getOpenAPIV3Schema; +/** + * Service that can register the composite resource together with a function, + * which can also add other function to the pipeline definition + */ public class CrossplaneCompositeResourceService { - - public static > void registerOrUpdateCompositeResource(String functionName, - List additionalFunctions, - T functionDefinition, + /** + * Register or update the composite resource definition using the provided client. + * The client needs access to register the types + * + * @param pipelineFunctions A list of functionnames to add to the composition pipeline + * @param compositionDefinition The object that has the composition definiton + * @param kubernetesClient The client to use to register the definition + * @param Must extend CustomResource + */ + public static > void registerOrUpdateCompositeResource(List pipelineFunctions, + T compositionDefinition, KubernetesClient kubernetesClient) { - CompositeResourceDefinition compositeResourceDefinition = createCompositeResourceDefinition(functionDefinition); + CompositeResourceDefinition compositeResourceDefinition = createCompositeResourceDefinition(compositionDefinition); registerOrUpdateCompositeResourceDefinition(compositeResourceDefinition, kubernetesClient); - Composition composition = createCompositionDefinition(functionName, additionalFunctions, functionDefinition); + Composition composition = createCompositionDefinition(pipelineFunctions, compositionDefinition); registerOrUpdateCompositeResourceDefinition(composition, kubernetesClient); @@ -52,41 +63,49 @@ public class CrossplaneCompositeResourceService { } } - public static > CompositeResourceDefinition createCompositeResourceDefinition(T functionDefinition) { //}, Class functionMixin) { + /** + * Create a CompositeResourceDefinition based on the provided CustomResource + * If Namespaced, ClaimNames will be added in addition to Names. + * + * @param compositionDefinition The composition definition + * @return A CompositeResourceDefintion based on the provided CustomResource + * @param Must extend CustomResource + */ + public static > CompositeResourceDefinition createCompositeResourceDefinition(T compositionDefinition) { //}, Class functionMixin) { CompositeResourceDefinition compositeResourceDefinition = new CompositeResourceDefinition(); - compositeResourceDefinition.setMetadata(CrossplaneMetadataBuilder.createMetadata(functionDefinition.getCRDName())); + compositeResourceDefinition.setMetadata(CrossplaneMetadataBuilder.createMetadata(compositionDefinition.getCRDName())); CompositeResourceDefinitionSpec spec = new CompositeResourceDefinitionSpec(); - spec.setGroup(functionDefinition.getGroup()); + spec.setGroup(compositionDefinition.getGroup()); String namePrefix = ""; - if (functionDefinition instanceof Namespaced) { + if (compositionDefinition instanceof Namespaced) { ClaimNames claimNames = new ClaimNames(); - claimNames.setKind(functionDefinition.getKind()); - claimNames.setPlural(functionDefinition.getPlural()); - claimNames.setSingular(functionDefinition.getSingular()); + claimNames.setKind(compositionDefinition.getKind()); + claimNames.setPlural(compositionDefinition.getPlural()); + claimNames.setSingular(compositionDefinition.getSingular()); spec.setClaimNames(claimNames); namePrefix = "x"; } Names names = new Names(); - names.setKind(namePrefix + functionDefinition.getKind()); - names.setPlural(namePrefix + functionDefinition.getPlural()); - names.setSingular(namePrefix + functionDefinition.getSingular()); + names.setKind(namePrefix + compositionDefinition.getKind()); + names.setPlural(namePrefix + compositionDefinition.getPlural()); + names.setSingular(namePrefix + compositionDefinition.getSingular()); spec.setNames(names); Versions versions = new Versions(); - versions.setName(functionDefinition.getVersion()); + versions.setName(compositionDefinition.getVersion()); // This is not 100%. isStorage vs referencable. Need to check the crossplan docs - versions.setReferenceable(functionDefinition.isStorage()); - versions.setServed(functionDefinition.isServed()); + versions.setReferenceable(compositionDefinition.isStorage()); + versions.setServed(compositionDefinition.isServed()); Schema schema = new Schema(); - schema.setOpenAPIV3Schema(getOpenAPIV3Schema(functionDefinition.getClass(), CrossplaneCompositeResourceMixin.class)); + schema.setOpenAPIV3Schema(getOpenAPIV3Schema(compositionDefinition.getClass(), CrossplaneCompositeResourceMixin.class)); versions.setSchema(schema); spec.setVersions(List.of(versions)); @@ -108,26 +127,23 @@ public class CrossplaneCompositeResourceService { } private static > Composition createCompositionDefinition( - String functionName, List additionalFunctions, - T functionDefinition) { + List pipelineFunctions, T compositionDefinition) { Composition composition = new Composition(); - composition.setMetadata(CrossplaneMetadataBuilder.createMetadata(functionDefinition.getKind().toLowerCase() + "-composition")); + composition.setMetadata(CrossplaneMetadataBuilder.createMetadata(compositionDefinition.getKind().toLowerCase() + "-composition")); CompositionSpec compositionSpec = new CompositionSpec(); CompositeTypeRef compositeTypeRef = new CompositeTypeRef(); - compositeTypeRef.setKind(functionDefinition.getKind()); - compositeTypeRef.setApiVersion(functionDefinition.getApiVersion()); + compositeTypeRef.setKind(compositionDefinition.getKind()); + compositeTypeRef.setApiVersion(compositionDefinition.getApiVersion()); compositionSpec.setCompositeTypeRef(compositeTypeRef); compositionSpec.setMode(CompositionSpec.Mode.PIPELINE); List pipelineList = new ArrayList<>(); - pipelineList.add(createPipeline(functionName)); - - additionalFunctions.forEach(s -> pipelineList.add(createPipeline(s))); + pipelineFunctions.forEach(s -> pipelineList.add(createPipeline(s))); compositionSpec.setPipeline(pipelineList); composition.setSpec(compositionSpec); diff --git a/crossplane-function-springboot-starter/src/main/java/io/crossplane/compositefunctions/starter/registration/CrossplanJsonSchemaGenerator.java b/crossplane-function-springboot-starter/src/main/java/io/crossplane/compositefunctions/starter/registration/CrossplaneJsonSchemaGenerator.java similarity index 86% rename from crossplane-function-springboot-starter/src/main/java/io/crossplane/compositefunctions/starter/registration/CrossplanJsonSchemaGenerator.java rename to crossplane-function-springboot-starter/src/main/java/io/crossplane/compositefunctions/starter/registration/CrossplaneJsonSchemaGenerator.java index 1b61aa2..4d95937 100644 --- a/crossplane-function-springboot-starter/src/main/java/io/crossplane/compositefunctions/starter/registration/CrossplanJsonSchemaGenerator.java +++ b/crossplane-function-springboot-starter/src/main/java/io/crossplane/compositefunctions/starter/registration/CrossplaneJsonSchemaGenerator.java @@ -12,8 +12,17 @@ import io.fabric8.kubernetes.api.model.apiextensions.v1.JSONSchemaProps; import java.io.IOException; import java.util.stream.Stream; -public class CrossplanJsonSchemaGenerator { +/** + * Generator of OpenApiV3Schema used when creating CompositeResourceDefinition + */ +public class CrossplaneJsonSchemaGenerator { + /** + * Create the OpenApiV3Schema + * @param clazz The class to create the schema from + * @param mixin A mixin to use when Jackson maps the class + * @return A OpenAPIV3Schema based on the given class + */ public static OpenAPIV3Schema getOpenAPIV3Schema(Class clazz, Class mixin) { try { ObjectMapper mapper = new ObjectMapper(); @@ -52,6 +61,11 @@ public class CrossplanJsonSchemaGenerator { } + /** + * Get the JSONSchemaProps from the class + * @param clazz The class to get the schema from + * @return The schemaprops based on the provided class + */ public static JSONSchemaProps getJsonSchema(Class clazz) { try { ObjectMapper mapper = new ObjectMapper(); @@ -73,7 +87,9 @@ public class CrossplanJsonSchemaGenerator { } - + /** + * Class just use to ignore the ID property that automatically gets added. + */ private abstract class IdIgnorer { @JsonIgnore diff --git a/crossplane-function-springboot-starter/src/main/java/io/crossplane/compositefunctions/starter/registration/CrossplaneMetadataBuilder.java b/crossplane-function-springboot-starter/src/main/java/io/crossplane/compositefunctions/starter/registration/CrossplaneMetadataBuilder.java index 565fdc3..20d9a68 100644 --- a/crossplane-function-springboot-starter/src/main/java/io/crossplane/compositefunctions/starter/registration/CrossplaneMetadataBuilder.java +++ b/crossplane-function-springboot-starter/src/main/java/io/crossplane/compositefunctions/starter/registration/CrossplaneMetadataBuilder.java @@ -6,24 +6,51 @@ import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; import java.util.LinkedHashMap; import java.util.Map; +/** + * Convinience methods to create the Metadata object in any kubernetes resource + */ public class CrossplaneMetadataBuilder { private CrossplaneMetadataBuilder() { } + /** + * Create metadata with name + * @param name The name of the resource + * @return The metdata object based on the input + */ + public static ObjectMeta createMetadata(String name) { + return createMetadata(name, null); + } + + /** + * Create metadata with name and namespace + * @param name The name of the resource + * @param namespace The namespace of the resource + * @return The metdata object based on the input + */ public static ObjectMeta createMetadata(String name, String namespace) { return createMetadata(name, namespace, null); } + /** + * Create metadata with name, namespace and annotations + * @param name The name of the resource + * @param namespace The namespace of the resource + * @param annotations Annotations to add to the metadata + * @return The metdata object based on the input + */ public static ObjectMeta createMetadata(String name, String namespace, Map annotations) { return new ObjectMetaBuilder().withName(name).withNamespace(namespace).withAnnotations(annotations).build(); } - public static ObjectMeta createMetadata(String name) { - return createMetadata(name, null); - } - + /** + * Add extra metadata to a Metadata object + * @param annotations The extra metadata to add + * @param objectMeta The metadata object to add it to + * @return The metadata with the added annotations + */ public static ObjectMeta addAnnotations(Map annotations, ObjectMeta objectMeta) { Map existingAnnotations = objectMeta.getAnnotations(); diff --git a/pom.xml b/pom.xml index c400f25..047dc1a 100644 --- a/pom.xml +++ b/pom.xml @@ -29,7 +29,7 @@ 6.13.0 1.7.1 3.25.1 - 1.64.0 + 1.63.0 1.3.5 2.0.13 2.17.1 @@ -100,43 +100,10 @@ io.grpc - grpc-protobuf - ${grpc.version} - - - io.grpc - grpc-stub - ${grpc.version} - - - io.grpc - grpc-core - ${grpc.version} - - - io.grpc - grpc-api - ${grpc.version} - - - io.grpc - grpc-util - ${grpc.version} - - - io.grpc - grpc-services - ${grpc.version} - - - io.grpc - grpc-inprocess - ${grpc.version} - - - io.grpc - grpc-netty-shaded + grpc-bom ${grpc.version} + import + pom jakarta.annotation