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

Hooks incorrectly watch different apiVersions with the same Kind #306

Open
wrasdf opened this issue Jul 5, 2021 · 1 comment
Open

Hooks incorrectly watch different apiVersions with the same Kind #306

wrasdf opened this issue Jul 5, 2021 · 1 comment
Labels
question Further information is requested

Comments

@wrasdf
Copy link

wrasdf commented Jul 5, 2021

context

We have two different apiVersions for our aurora dababase crds:

  • aurora.rds.cloud/v1beta1
  • aurora.rds.cloud/v1beta2

And have two startup.sh for both v1beta1 & v1beta2, but in different folder.

Screen Shot 2021-07-05 at 2 08 03 pm

Take v1beta2 of standup.sh details as below:

#!/bin/bash

set -eEuo pipefail

source /app/lib/functions.sh

function __config__() {
  cat << EOF
    configVersion: v1
    onStartup: 5
    kubernetes:
    - name: startup::cluster
      apiVersion: aurora.rds.cloud/v1beta2
      kind: cluster
      keepFullObjectsInMemory: false
      allowFailure: true
      executeHookOnEvent: []
      executeHookOnSynchronization: true
      jqFilter: |
        {
          kind: .kind,
          apiVersion: .apiVersion,
          name: .metadata.name,
          namespace: .metadata.namespace,
          spec: .spec
        }
EOF
}

function __main__() {

  type="$(context::jq -r '.type')"
  context::jq -r '.' > /tmp/cluster-v1beta2-onStartup.out
  # synchronisation
  for i in $(seq 0 "$(context::jq -r '(.objects | length) - 1')"); do
    obj="$(context::jq -r '.objects['"$i"'].filterResult')"
    echo "startup::${type}"
    ......
  done

}

hook::run "$@"

Expected behavior (what you expected to happen):

As we have to support 2 versions for our operator, we expected:

  • With the same Kind
    • v1beta1 hooks could only watch the apiVersion of aurora.rds.cloud/v1beta1.
    • v1beta2 hooks could only focus on apiVersion of aurora.rds.cloud/v1beta2

Actual behavior (what actually happened):

  • With the same Kind
    • v1beta1 hooks watch both v1beta1 & v1beta2 resource
    • v1beta2 hooks watch both v1beta1 & v1beta2 resource

eg:

  • the apiVersion of delete-postgres-v1beta2 -> aurora.rds.cloud/v1beta2

Screen Shot 2021-07-05 at 2 12 07 pm

Error outputs as below:

bash-5.0# cat /tmp/cluster-v1beta1-addedModified.out
{
  "binding": "modified::cluster",
  "filterResult": {
    "apiVersion": "aurora.rds.cloud/v1beta1",
    "kind": "cluster",
    "name": "delete-postgres-v1beta2",
    "namespace": "pe",
    "spec": {
      "database_name": "postgres",
      "deletion_protection": false,
      "engine_mode": "provisioned",
      "engine_version": 12.6,
      "instance_class": "db.r5.large",
      "postgres": true,
      "primary_instance_count": 1,
      "skip_final_snapshot": true
    }
  },
  "type": "Event",
  "watchEvent": "Added"
}

Correct outputs as below:

bash-5.0# cat /tmp/cluster-v1beta2-addedModified.out
{
  "binding": "modified::cluster",
  "filterResult": {
    "apiVersion": "aurora.rds.cloud/v1beta2",
    "kind": "cluster",
    "name": "delete-postgres-v1beta2",
    "namespace": "pe",
    "spec": {
      "database_name": "postgres",
      "deletion_protection": false,
      "engine_mode": "provisioned",
      "engine_version": 12.6,
      "instance_class": "db.r5.large",
      "postgres": true,
      "primary_instance_count": 1,
      "skip_final_snapshot": true
    }
  },
  "type": "Event",
  "watchEvent": "Added"
}

If the hooks config with the same Kind but different apiVersion:

  • context::jq -r '.' could return the incorrect apiVersion as above ☝️

Environment:

  • Shell-operator version: v1.0.1
  • Kubernetes version: 1.19.6
  • Installation type (kubectl apply, helm chart, etc.): kubectl apply
@wrasdf wrasdf changed the title hooks could not watch different apiVersion hooks could not watch different apiVersion with the same Kind Jul 5, 2021
@wrasdf wrasdf changed the title hooks could not watch different apiVersion with the same Kind Hooks incorrectly watch different apiVersion with the same Kind Jul 5, 2021
@wrasdf wrasdf changed the title Hooks incorrectly watch different apiVersion with the same Kind Hooks incorrectly watch different apiVersions with the same Kind Jul 5, 2021
@diafour
Copy link
Contributor

diafour commented Jul 19, 2021

Hello! The behavior you've described is correct. In short, apiVersion field is not a filter but more like a hint for Kubernetes API-server.

It's not an issue inside the shell-operator but a result of the machinery inside Kubernetes. Here is the link that explains version handling for CRDs: https://kubernetes.io/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definition-versioning/
Also, check the documentation for conversion hooks: BINDING_CONVERSION

@diafour diafour added the question Further information is requested label Aug 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants