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

Bug: The syncMode written in EventTrigger is not being transferred to ClusterProfile. #465

Closed
kahirokunn opened this issue Feb 3, 2025 · 2 comments
Assignees

Comments

@kahirokunn
Copy link
Contributor

The written EventTrigger is as follows.

---
apiVersion: lib.projectsveltos.io/v1beta1
kind: EventSource
metadata:
  name: detect-tls-secret
spec:
  collectResources: true
  resourceSelectors:
    - group: ""
      version: v1
      kind: Secret
      namespace: mgmt
      evaluate: |
        function evaluate()
          hs = {}
          hs.matching = false
          if obj.type ~= nil and obj.type == "kubernetes.io/tls" then
            hs.matching = true
          end
          return hs
        end
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: transform-tls-secret
  namespace: mgmt
  annotations:
    projectsveltos.io/instantiate: ok
data:
  tls-secret.yaml: |
    apiVersion: v1
    kind: Secret
    metadata:
      name: {{ .Resource.metadata.name }}
      namespace: {{ .Resource.metadata.namespace }}
      {{ if .Resource.metadata.labels }}
      labels:
        {{ range $key, $value := .Resource.metadata.labels }}
          {{ $key }}: {{ $value }}
        {{ end }}
      {{ end }}
    type: {{ .Resource.type }}
    data:
      {{ range $key, $value := .Resource.data }}
        {{ $key }}: {{ $value }}
      {{ end }}
---
apiVersion: lib.projectsveltos.io/v1beta1
kind: EventTrigger
metadata:
  name: transform-tls-secret
spec:
  sourceClusterSelector:
    matchLabels:
      role: mgmt
  destinationClusterSelector:
    matchLabels:
      role: worker
  eventSourceName: detect-tls-secret
  oneForEvent: true
  syncMode: ContinuousWithDriftDetection  # TODO: これ、ClusterProfileに転送されてない
  policyRefs:
    - name: transform-tls-secret
      namespace: mgmt
      kind: ConfigMap

The generated ClusterProfile is as follows.
Is this perhaps a processing description omission? 👀

apiVersion: config.projectsveltos.io/v1beta1
kind: ClusterProfile
metadata:
  creationTimestamp: "2025-02-03T08:15:05Z"
  finalizers:
  - clusterprofilefinalizer.projectsveltos.io
  generation: 1
  labels:
    eventtrigger.lib.projectsveltos.io/clusterNamespace: mgmt
    eventtrigger.lib.projectsveltos.io/clustername: mgmt
    eventtrigger.lib.projectsveltos.io/clustertype: Sveltos
    eventtrigger.lib.projectsveltos.io/eventreportname: detect-tls-secret
    eventtrigger.lib.projectsveltos.io/eventtriggername: transform-tls-secret
    eventtrigger.lib.projectsveltos.io/refname: transform-tls-secret
    eventtrigger.lib.projectsveltos.io/refnamespace: mgmt
    eventtrigger.lib.projectsveltos.io/resourcename: sample-secret
    eventtrigger.lib.projectsveltos.io/resourcenamespace: mgmt
    projectsveltos.io/cluster-name: clusterapi-workload
    projectsveltos.io/cluster-profile-name: sveltos-ijz6vb348vvuix4g8ydv
    projectsveltos.io/cluster-type: Capi
  name: sveltos-ijz6vb348vvuix4g8ydv
  resourceVersion: "158675"
  uid: 99dd0dfc-0c08-4183-8b08-b029a1cf0529
spec:
  clusterSelector:
    matchLabels:
      role: worker
  continueOnConflict: false
  continueOnError: false
  policyRefs:
  - deploymentType: Remote
    kind: ConfigMap
    name: sveltos-uw29vfoyuk1n3sh3v8gb
    namespace: projectsveltos
  reloader: false
  stopMatchingBehavior: WithdrawPolicies
  syncMode: Continuous
  tier: 100
status:
  matchingClusters:
  - apiVersion: cluster.x-k8s.io/v1beta1
    kind: Cluster
    name: clusterapi-workload
    namespace: default
@gianlucam76 gianlucam76 self-assigned this Feb 3, 2025
@gianlucam76
Copy link
Member

Thank you @kahirokunn

This is a bug. The syncMode must be copied over to ClusterProfile.

gianlucam76 added a commit to gianlucam76/event-manager that referenced this issue Feb 3, 2025
CloudEventAction can be expressed as a template. So whether to
create or delete can be a function of CloudEvent properties.

For instance

````yaml
apiVersion: lib.projectsveltos.io/v1beta1
kind: EventSource
metadata:
  name: user-operation
spec:
  messagingMatchCriteria:
  - subject: "user-operation"
    cloudEventSource: "auth.example.com/operation"
---
apiVersion: lib.projectsveltos.io/v1beta1
kind: EventTrigger
metadata:
  name: manage-namespace
spec:
  sourceClusterSelector:
    matchLabels:
      env: fv
  eventSourceName: user-operation
  oneForEvent: true
  syncMode: ContinuousWithDriftDetection
  cloudEventAction: "{{ if eq .CloudEvent.type 'auth.example.com.logout' }}Delete{{ else }}Create{{ end }}"
  policyRefs:
  - name: namespace
    namespace: default
    kind: ConfigMap
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: namespace
  namespace: default
  annotations:
    projectsveltos.io/instantiate: ok
data:
  namespace.yaml: |
    kind: Namespace
    apiVersion: v1
    metadata:
      name: {{ .CloudEvent.subject }}
```

when CloudEvent is for instance

```
CLOUDEVENT_JSON=$(cat << EOF
{
  "specversion": "1.0",
  "type": "auth.example.com.login",
  "source": "auth.example.com/operation",
  "id": "10001",
  "subject": "mgianluc",
  "datacontenttype": "application/json",
  "data": {
    "message": "Hello from bash!"
  }
}
EOF
)
```
namespace is created.

When CloudEvent is

```
CLOUDEVENT_JSON=$(cat << EOF
{
  "specversion": "1.0",
  "type": "auth.example.com.logòut",
  "source": "auth.example.com/operation",
  "id": "10001",
  "subject": "mgianluc",
  "datacontenttype": "application/json",
  "data": {
    "message": "Hello from bash!"
  }
}
EOF
)
```

namespace is deleted.

This PR also fixes this [bug](projectsveltos/sveltos#465).
gianlucam76 added a commit to gianlucam76/event-manager that referenced this issue Feb 3, 2025
CloudEventAction can be expressed as a template. So whether to
create or delete can be a function of CloudEvent properties.

For instance

````yaml
apiVersion: lib.projectsveltos.io/v1beta1
kind: EventSource
metadata:
  name: user-operation
spec:
  messagingMatchCriteria:
  - subject: "user-operation"
    cloudEventSource: "auth.example.com/operation"
---
apiVersion: lib.projectsveltos.io/v1beta1
kind: EventTrigger
metadata:
  name: manage-namespace
spec:
  sourceClusterSelector:
    matchLabels:
      env: fv
  eventSourceName: user-operation
  oneForEvent: true
  syncMode: ContinuousWithDriftDetection
  cloudEventAction: "{{ if eq .CloudEvent.type 'auth.example.com.logout' }}Delete{{ else }}Create{{ end }}"
  policyRefs:
  - name: namespace
    namespace: default
    kind: ConfigMap
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: namespace
  namespace: default
  annotations:
    projectsveltos.io/instantiate: ok
data:
  namespace.yaml: |
    kind: Namespace
    apiVersion: v1
    metadata:
      name: {{ .CloudEvent.subject }}
```

when CloudEvent is for instance

```
CLOUDEVENT_JSON=$(cat << EOF
{
  "specversion": "1.0",
  "type": "auth.example.com.login",
  "source": "auth.example.com/operation",
  "id": "10001",
  "subject": "mgianluc",
  "datacontenttype": "application/json",
  "data": {
    "message": "Hello from bash!"
  }
}
EOF
)
```
namespace is created.

When CloudEvent is

```
CLOUDEVENT_JSON=$(cat << EOF
{
  "specversion": "1.0",
  "type": "auth.example.com.logòut",
  "source": "auth.example.com/operation",
  "id": "10001",
  "subject": "mgianluc",
  "datacontenttype": "application/json",
  "data": {
    "message": "Hello from bash!"
  }
}
EOF
)
```

namespace is deleted.

This PR also fixes this [bug](projectsveltos/sveltos#465).
gianlucam76 added a commit to gianlucam76/event-manager that referenced this issue Feb 3, 2025
CloudEventAction can be expressed as a template. So whether to
create or delete can be a function of CloudEvent properties.

For instance

````yaml
apiVersion: lib.projectsveltos.io/v1beta1
kind: EventSource
metadata:
  name: user-operation
spec:
  messagingMatchCriteria:
  - subject: "user-operation"
    cloudEventSource: "auth.example.com/operation"
---
apiVersion: lib.projectsveltos.io/v1beta1
kind: EventTrigger
metadata:
  name: manage-namespace
spec:
  sourceClusterSelector:
    matchLabels:
      env: fv
  eventSourceName: user-operation
  oneForEvent: true
  syncMode: ContinuousWithDriftDetection
  cloudEventAction: "{{ if eq .CloudEvent.type 'auth.example.com.logout' }}Delete{{ else }}Create{{ end }}"
  policyRefs:
  - name: namespace
    namespace: default
    kind: ConfigMap
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: namespace
  namespace: default
  annotations:
    projectsveltos.io/instantiate: ok
data:
  namespace.yaml: |
    kind: Namespace
    apiVersion: v1
    metadata:
      name: {{ .CloudEvent.subject }}
```

when CloudEvent is for instance

```
CLOUDEVENT_JSON=$(cat << EOF
{
  "specversion": "1.0",
  "type": "auth.example.com.login",
  "source": "auth.example.com/operation",
  "id": "10001",
  "subject": "mgianluc",
  "datacontenttype": "application/json",
  "data": {
    "message": "Hello from bash!"
  }
}
EOF
)
```
namespace is created.

When CloudEvent is

```
CLOUDEVENT_JSON=$(cat << EOF
{
  "specversion": "1.0",
  "type": "auth.example.com.logòut",
  "source": "auth.example.com/operation",
  "id": "10001",
  "subject": "mgianluc",
  "datacontenttype": "application/json",
  "data": {
    "message": "Hello from bash!"
  }
}
EOF
)
```

namespace is deleted.

This PR also fixes this [bug](projectsveltos/sveltos#465).
@gianlucam76
Copy link
Member

Fix will be in v0.46.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants