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

Ability to watch referenced or managed Kubernetes resources #235

Merged
merged 19 commits into from
May 10, 2024

Conversation

turkenh
Copy link
Collaborator

@turkenh turkenh commented May 3, 2024

Description of your changes

This PR introduces the capability of watching referenced or managed Kubernetes resources as an "alpha feature".

When provider started with --enable-watches argument, it will be possible to configure an Object to watch relevant resources by setting spec.watch: true which is off by default.

The implementation is heavily based on the realtime compositions in Crossplane (as suggested by @sttts), however, we still have a good amount of divergence due to the difference between use cases.

apiVersion: kubernetes.crossplane.io/v1alpha2
kind: Object
metadata:
  name: sample-object
spec:
  watch: true # Watch for changes to on the Configmap
  forProvider:
    manifest:
      apiVersion: v1
      kind: ConfigMap
      metadata:
        namespace: default
      data:
        sample-key: sample-value

Fixes #159
Fixes #212
Fixes #164
Fixes #138

I have:

  • Read and followed Crossplane's contribution process.
  • Run make reviewable test to ensure this PR is ready for review.

How has this code been tested

  1. Deploy provider kubernetes watches feature enabled with the help of the following:
apiVersion: pkg.crossplane.io/v1
kind: Provider
metadata:
  name: crossplane-contrib-provider-kubernetes
spec:
  package: "index.docker.io/turkenh/provider-kubernetes:v0.14.0-rc0.12.gc580206" # custom build from this PR
  runtimeConfigRef:
    name: provider-kubernetes
---
apiVersion: pkg.crossplane.io/v1beta1
kind: DeploymentRuntimeConfig
metadata:
  name: provider-kubernetes
spec:
  deploymentTemplate:
    spec:
      selector: {}
      strategy: {}
      template:
        spec:
          containers:
          - args:
            - --enable-watches
            name: package-runtime
  1. Deploy the following Object which has a reference to a configmap and managing another configmap:
---
apiVersion: kubernetes.crossplane.io/v1alpha2
kind: Object
metadata:
  name: foo
spec:
  watch: true
  references:
  # Use patchesFrom to patch field from other k8s resource to this object
  - patchesFrom:
      apiVersion: v1
      kind: ConfigMap
      name: bar
      namespace: default
      fieldPath: data.sample-key
    toFieldPath: data.sample-key-from-bar
  forProvider:
    manifest:
      apiVersion: v1
      kind: ConfigMap
      metadata:
        namespace: default
      data:
        sample-key: sample-value
  providerConfigRef:
    name: kubernetes-provider
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: bar
  namespace: default
data:
  sample-key: sample-value
  1. Touch (e.g. add a random label) referenced configmap (bar) and check for the log line with message "Enqueueing Object because referenced resource changed"

  2. Touch (e.g. add a random label) managed configmap (foo) and check for the log line with message "Enqueueing Object because referenced resource changed"

turkenh added 12 commits May 1, 2024 00:32
Signed-off-by: Hasan Turken <turkenh@gmail.com>
Signed-off-by: Hasan Turken <turkenh@gmail.com>
Signed-off-by: Hasan Turken <turkenh@gmail.com>
Signed-off-by: Hasan Turken <turkenh@gmail.com>
Signed-off-by: Hasan Turken <turkenh@gmail.com>
Signed-off-by: Hasan Turken <turkenh@gmail.com>
Signed-off-by: Hasan Turken <turkenh@gmail.com>
Signed-off-by: Hasan Turken <turkenh@gmail.com>
Signed-off-by: Hasan Turken <turkenh@gmail.com>
Signed-off-by: Hasan Turken <turkenh@gmail.com>
Signed-off-by: Hasan Turken <turkenh@gmail.com>
@turkenh turkenh changed the title Watching referenced or managed Kubernetes resources Ability to watch referenced or managed Kubernetes resources May 3, 2024
apis/object/v1alpha1/types.go Outdated Show resolved Hide resolved
@turkenh turkenh requested a review from sttts May 3, 2024 13:01
Signed-off-by: Hasan Turken <turkenh@gmail.com>
internal/clients/clients.go Outdated Show resolved Hide resolved
Signed-off-by: Hasan Turken <turkenh@gmail.com>
Signed-off-by: Hasan Turken <turkenh@gmail.com>
Signed-off-by: Hasan Turken <turkenh@gmail.com>
@turkenh turkenh requested a review from sttts May 10, 2024 09:36
Signed-off-by: Hasan Turken <turkenh@gmail.com>
Signed-off-by: Hasan Turken <turkenh@gmail.com>
Signed-off-by: Hasan Turken <turkenh@gmail.com>
@turkenh turkenh requested a review from sttts May 10, 2024 15:31
@turkenh
Copy link
Collaborator Author

turkenh commented May 10, 2024

From e2e test logs:

    logger.go:42: 15:29:35 | case/0-apply | running command: [/home/runner/work/provider-kubernetes/provider-kubernetes/examples/object/testhooks/validate-watching.sh]
    logger.go:42: 15:29:38 | case/0-apply | Enabling watch feature for the provider
    logger.go:42: 15:29:39 | case/0-apply | deploymentruntimeconfig.pkg.crossplane.io/runtimeconfig-provider-kubernetes patched
    logger.go:42: 15:29:42 | case/0-apply | Patching referenced secret
    logger.go:42: 15:29:42 | case/0-apply | secret/bar patched
    logger.go:42: 15:29:45 | case/0-apply | Checking if the managed secret has been updated
    logger.go:42: 15:29:45 | case/0-apply | Checking if the managed secret has been updated...Success
    logger.go:42: 15:29:45 | case/0-apply | Patching managed secret
    logger.go:42: 15:29:45 | case/0-apply | secret/foo patched
    logger.go:42: 15:29:48 | case/0-apply | Checking if the object grabbed the new value at status.atProvider
    logger.go:42: 15:29:48 | case/0-apply | Checking if the object grabbed the new value at status.atProvider...Success
    logger.go:42: 15:29:48 | case/0-apply | Successfully validated the watch feature!
    logger.go:42: 15:29:48 | case/0-apply | Disabling watch feature for the provider

WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks a little distorted:

// Copyright 2024 The Crossplane Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, we really have that format in Crossplane?

@sttts
Copy link

sttts commented May 10, 2024

Lgtm

@turkenh turkenh merged commit a701a79 into crossplane-contrib:main May 10, 2024
7 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants