-
Notifications
You must be signed in to change notification settings - Fork 87
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 #246 from turkenh/ssa-second-attempt
Add Alpha Support for Server Side Apply (2nd attempt)
- Loading branch information
Showing
48 changed files
with
117,484 additions
and
222 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
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,24 @@ | ||
# Note: This example is for the alpha feature of server side apply. | ||
# It requires the provider to be started with the --enable-server-side-apply flag. | ||
apiVersion: kubernetes.crossplane.io/v1alpha2 | ||
kind: Object | ||
metadata: | ||
name: sample-service-labeler | ||
spec: | ||
# Note: This resource will only patch/update the manifest below. | ||
# It will not delete or create the resource. | ||
# As a limitation, it will not clean up the changes it made during its deletion. | ||
# This requires the Server Side Apply feature to be enabled in the provider | ||
# with the --enable-server-side-apply flag. | ||
managementPolicies: ["Observe", "Update"] | ||
forProvider: | ||
manifest: | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: sample-service | ||
namespace: default | ||
labels: | ||
another-key: another-value | ||
providerConfigRef: | ||
name: kubernetes-provider |
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,29 @@ | ||
# Note: This example is for the alpha feature of server side apply. | ||
# It requires the provider to be started with the --enable-server-side-apply flag. | ||
apiVersion: kubernetes.crossplane.io/v1alpha2 | ||
kind: Object | ||
metadata: | ||
name: sample-service-owner | ||
annotations: | ||
uptest.upbound.io/pre-assert-hook: testhooks/enable-ssa.sh | ||
uptest.upbound.io/post-assert-hook: testhooks/validate-ssa.sh | ||
uptest.upbound.io/timeout: "60" | ||
spec: | ||
forProvider: | ||
manifest: | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: sample-service | ||
namespace: default | ||
labels: | ||
some-key: some-value | ||
spec: | ||
selector: | ||
app.kubernetes.io/name: MyApp | ||
ports: | ||
- protocol: TCP | ||
port: 80 | ||
targetPort: 9376 | ||
providerConfigRef: | ||
name: kubernetes-provider |
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,5 @@ | ||
#!/usr/bin/env bash | ||
set -aeuo pipefail | ||
|
||
echo "Enabling ssa feature for the provider" | ||
${KUBECTL} patch deploymentruntimeconfig runtimeconfig-provider-kubernetes --type='json' -p='[{"op":"replace","path":"/spec/deploymentTemplate/spec/template/spec/containers/0/args", "value":["--debug", "--enable-server-side-apply"]}]' |
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,25 @@ | ||
#!/usr/bin/env bash | ||
set -aeuo pipefail | ||
|
||
# This script is used to validate the ssa feature, triggered by the | ||
# uptest framework via `uptest.upbound.io/post-assert-hook`: https://github.com/crossplane/uptest/tree/e64457e2cce153ada54da686c8bf96143f3f6329?tab=readme-ov-file#hooks | ||
|
||
LABELER_OBJECT="examples/object/object-ssa-labeler.yaml" | ||
${KUBECTL} apply -f ${LABELER_OBJECT} | ||
${KUBECTL} wait -f ${LABELER_OBJECT} --for condition=ready --timeout=1m | ||
|
||
if ! ${KUBECTL} get service sample-service -o jsonpath='{.metadata.annotations}' | grep -v "last-applied-configuration"; then # This annotation should not be present when SSA is enabled | ||
echo "SSA validation failed! Annotation 'last-applied-configuration' should not exist when SSA is enabled!" | ||
#exit 1 | ||
fi | ||
if ! (${KUBECTL} get service sample-service -o jsonpath='{.metadata.labels.some-key}' | grep -q "some-value" && ${KUBECTL} get service sample-service -o jsonpath='{.metadata.labels.another-key}' | grep -q "another-value"); then | ||
echo "SSA validation failed! Labels 'some-key' and 'another-key' from both Objects should exist with values 'some-value' and 'another-value' respectively!" | ||
#exit 1 | ||
fi | ||
echo "Successfully validated the SSA feature!" | ||
|
||
${KUBECTL} delete -f ${LABELER_OBJECT} | ||
|
||
echo "Disabling SSA feature for the provider" | ||
${KUBECTL} patch deploymentruntimeconfig runtimeconfig-provider-kubernetes --type='json' -p='[{"op":"replace","path":"/spec/deploymentTemplate/spec/template/spec/containers/0/args", "value":["--debug"]}]' | ||
|
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
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,31 @@ | ||
package fake | ||
|
||
import ( | ||
"context" | ||
|
||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" | ||
|
||
"github.com/crossplane-contrib/provider-kubernetes/apis/object/v1alpha2" | ||
) | ||
|
||
// A ResourceSyncer is a fake ResourceSyncer. | ||
type ResourceSyncer struct { | ||
GetObservedStateFn func(ctx context.Context, obj *v1alpha2.Object, current *unstructured.Unstructured) (*unstructured.Unstructured, error) | ||
GetDesiredStateFn func(ctx context.Context, obj *v1alpha2.Object, manifest *unstructured.Unstructured) (*unstructured.Unstructured, error) | ||
SyncResourceFn func(ctx context.Context, obj *v1alpha2.Object, desired *unstructured.Unstructured) (*unstructured.Unstructured, error) | ||
} | ||
|
||
// GetObservedState calls the GetObservedStateFn. | ||
func (r *ResourceSyncer) GetObservedState(ctx context.Context, obj *v1alpha2.Object, current *unstructured.Unstructured) (*unstructured.Unstructured, error) { | ||
return r.GetObservedStateFn(ctx, obj, current) | ||
} | ||
|
||
// GetDesiredState calls the GetDesiredStateFn. | ||
func (r *ResourceSyncer) GetDesiredState(ctx context.Context, obj *v1alpha2.Object, manifest *unstructured.Unstructured) (*unstructured.Unstructured, error) { | ||
return r.GetDesiredStateFn(ctx, obj, manifest) | ||
} | ||
|
||
// SyncResource calls the SyncResourceFn. | ||
func (r *ResourceSyncer) SyncResource(ctx context.Context, obj *v1alpha2.Object, desired *unstructured.Unstructured) (*unstructured.Unstructured, error) { | ||
return r.SyncResourceFn(ctx, obj, desired) | ||
} |
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.