crossplane-contrib / provider-upjet-gcp

Official GCP Provider for Crossplane by Upbound.
Apache License 2.0
66 stars 72 forks source link

[Bug]: Unable to refer the `notificationChannels` in GCP AlertPolicy using NotificationChannel name as documented #498

Closed avijitsarkar123 closed 1 month ago

avijitsarkar123 commented 6 months ago

Is there an existing issue for this?

Affected Resource(s)

Resource MRs required to reproduce the bug

NotificationChannel Manifest:

apiVersion: monitoring.gcp.upbound.io/v1beta1
kind: NotificationChannel
metadata:
  annotations:
    crossplane.io/external-create-pending: '2024-03-26T17:44:52Z'
    crossplane.io/external-create-succeeded: '2024-03-26T17:44:52Z'
    crossplane.io/external-name: >-
      projects/my-gcp-project/notificationChannels/10947831030092706776
    kubectl.kubernetes.io/last-applied-configuration: >
      {"apiVersion":"monitoring.gcp.upbound.io/v1beta1","kind":"NotificationChannel","metadata":{"annotations":{},"labels":{"app.kubernetes.io/instance":"my-sample-app","app.kubernetes.io/managed-by":"Helm","app.kubernetes.io/name":"my-sample-app","app.kubernetes.io/version":"0.0.5","helm.sh/chart":"my-sample-app-0.0.4"},"name":"my-sample-app-notification-email-channel"},"spec":{"forProvider":{"displayName":"my-sample-app
      email notification
      channel","labels":{"email_address":"myemail@example.com"},"type":"email"}}}
    upjet.crossplane.io/provider-meta: >-
      {"e2bfb730-ecaa-11e6-8f88-34363bc7c4c0":{"create":1200000000000,"delete":1200000000000,"update":1200000000000}}
  creationTimestamp: '2024-03-26T17:44:49Z'
  finalizers:
    - finalizer.managedresource.crossplane.io
  generation: 2
  labels:
    app.kubernetes.io/instance: my-sample-app
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/name: my-sample-app
    app.kubernetes.io/version: 0.0.5
    helm.sh/chart: my-sample-app-0.0.4
  managedFields:
    - apiVersion: monitoring.gcp.upbound.io/v1beta1
      fieldsType: FieldsV1
      fieldsV1:
        f:metadata:
          f:annotations:
            .: {}
            f:kubectl.kubernetes.io/last-applied-configuration: {}
          f:labels:
            .: {}
            f:app.kubernetes.io/instance: {}
            f:app.kubernetes.io/managed-by: {}
            f:app.kubernetes.io/name: {}
            f:app.kubernetes.io/version: {}
            f:helm.sh/chart: {}
        f:spec:
          .: {}
          f:deletionPolicy: {}
          f:forProvider:
            .: {}
            f:displayName: {}
            f:labels:
              .: {}
              f:email_address: {}
            f:type: {}
          f:providerConfigRef:
            .: {}
            f:name: {}
      manager: kubectl-client-side-apply
      operation: Update
      time: '2024-03-26T17:44:49Z'
    - apiVersion: monitoring.gcp.upbound.io/v1beta1
      fieldsType: FieldsV1
      fieldsV1:
        f:metadata:
          f:annotations:
            f:crossplane.io/external-create-pending: {}
            f:crossplane.io/external-create-succeeded: {}
            f:crossplane.io/external-name: {}
            f:upjet.crossplane.io/provider-meta: {}
          f:finalizers:
            .: {}
            v:"finalizer.managedresource.crossplane.io": {}
        f:spec:
          f:forProvider:
            f:enabled: {}
            f:project: {}
      manager: provider
      operation: Update
      time: '2024-03-26T17:45:06Z'
    - apiVersion: monitoring.gcp.upbound.io/v1beta1
      fieldsType: FieldsV1
      fieldsV1:
        f:status:
          .: {}
          f:atProvider:
            .: {}
            f:id: {}
            f:name: {}
            f:verificationStatus: {}
          f:conditions: {}
      manager: provider
      operation: Update
      subresource: status
      time: '2024-03-26T17:45:10Z'
  name: my-sample-app-notification-email-channel
  resourceVersion: '67126338'
  uid: cd775c5a-4434-4ec1-b9eb-1fad4fbd4318
  selfLink: >-
    /apis/monitoring.gcp.upbound.io/v1beta1/notificationchannels/my-sample-app-notification-email-channel
status:
  atProvider:
    id: >-
      projects/my-gcp-project/notificationChannels/10947831030092706776
    name: >-
      projects/my-gcp-project/notificationChannels/10947831030092706776
    verificationStatus: ''
  conditions:
    - lastTransitionTime: '2024-03-26T17:45:10Z'
      reason: Available
      status: 'True'
      type: Ready
    - lastTransitionTime: '2024-03-26T17:44:52Z'
      reason: ReconcileSuccess
      status: 'True'
      type: Synced
    - lastTransitionTime: '2024-03-26T17:44:58Z'
      reason: Success
      status: 'True'
      type: LastAsyncOperation
    - lastTransitionTime: '2024-03-26T17:44:58Z'
      reason: Finished
      status: 'True'
      type: AsyncOperation
spec:
  deletionPolicy: Delete
  forProvider:
    displayName: my-sample-app email notification channel
    enabled: true
    labels:
      email_address: myemail@example.com
    project: my-gcp-project
    type: email
  providerConfigRef:
    name: default

AlertPolicy Manifest

apiVersion: monitoring.gcp.upbound.io/v1beta1
kind: AlertPolicy
metadata:
  annotations:
    crossplane.io/external-create-failed: '2024-03-26T18:21:14Z'
    crossplane.io/external-create-pending: '2024-03-26T18:21:14Z'
    crossplane.io/external-create-succeeded: '2024-03-26T18:20:12Z'
    kubectl.kubernetes.io/last-applied-configuration: >
      {"apiVersion":"monitoring.gcp.upbound.io/v1beta1","kind":"AlertPolicy","metadata":{"annotations":{},"labels":{"app.kubernetes.io/instance":"my-sample-app","app.kubernetes.io/managed-by":"Helm","app.kubernetes.io/name":"my-sample-app","app.kubernetes.io/version":"0.0.5","helm.sh/chart":"my-sample-app-0.0.4"},"name":"my-sample-app-job-alert-policy"},"spec":{"forProvider":{"combiner":"OR","conditions":[{"conditionThreshold":[{"aggregations":[{"alignmentPeriod":"900s","crossSeriesReducer":"REDUCE_SUM","perSeriesAligner":"ALIGN_MEAN"}],"comparison":"COMPARISON_GT","duration":"900s","filter":"metric.type=\"prometheus.googleapis.com/kube_job_status_failed/gauge\"
      AND resource.type=\"prometheus_target\" AND
      resource.label.namespace=ka-dev-my-sample-app","thresholdValue":1}],"displayName":"my-sample-app
      job alert"}],"displayName":"my-sample-app job alert
      policy","enabled":true,"notificationChannels":["my-sample-app-notification-email-channel"]}}}
  creationTimestamp: '2024-03-26T17:44:47Z'
  finalizers:
    - finalizer.managedresource.crossplane.io
  generation: 3
  labels:
    app.kubernetes.io/instance: my-sample-app
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/name: my-sample-app
    app.kubernetes.io/version: 0.0.5
    helm.sh/chart: my-sample-app-0.0.4
    k8slens-edit-resource-version: v1beta1
  managedFields:
    - apiVersion: monitoring.gcp.upbound.io/v1beta1
      fieldsType: FieldsV1
      fieldsV1:
        f:metadata:
          f:labels:
            f:k8slens-edit-resource-version: {}
      manager: node-fetch
      operation: Update
      time: '2024-03-26T17:45:50Z'
    - apiVersion: monitoring.gcp.upbound.io/v1beta1
      fieldsType: FieldsV1
      fieldsV1:
        f:metadata:
          f:annotations:
            .: {}
            f:kubectl.kubernetes.io/last-applied-configuration: {}
          f:labels:
            .: {}
            f:app.kubernetes.io/instance: {}
            f:app.kubernetes.io/managed-by: {}
            f:app.kubernetes.io/name: {}
            f:app.kubernetes.io/version: {}
            f:helm.sh/chart: {}
        f:spec:
          .: {}
          f:deletionPolicy: {}
          f:forProvider:
            .: {}
            f:combiner: {}
            f:conditions: {}
            f:displayName: {}
            f:enabled: {}
            f:notificationChannels: {}
          f:providerConfigRef:
            .: {}
            f:name: {}
      manager: kubectl-client-side-apply
      operation: Update
      time: '2024-03-26T18:05:24Z'
    - apiVersion: monitoring.gcp.upbound.io/v1beta1
      fieldsType: FieldsV1
      fieldsV1:
        f:metadata:
          f:annotations:
            f:crossplane.io/external-create-failed: {}
            f:crossplane.io/external-create-pending: {}
            f:crossplane.io/external-create-succeeded: {}
          f:finalizers:
            .: {}
            v:"finalizer.managedresource.crossplane.io": {}
      manager: provider
      operation: Update
      time: '2024-03-26T18:21:14Z'
    - apiVersion: monitoring.gcp.upbound.io/v1beta1
      fieldsType: FieldsV1
      fieldsV1:
        f:status:
          .: {}
          f:atProvider: {}
          f:conditions: {}
      manager: provider
      operation: Update
      subresource: status
      time: '2024-03-26T18:21:14Z'
  name: my-sample-app-job-alert-policy
  resourceVersion: '67155187'
  uid: 0a3da036-5638-4963-942e-59d60616ee4c
  selfLink: >-
    /apis/monitoring.gcp.upbound.io/v1beta1/alertpolicies/my-sample-app-job-alert-policy
status:
  atProvider: {}
  conditions:
    - lastTransitionTime: '2024-03-26T17:44:49Z'
      reason: Creating
      status: 'False'
      type: Ready
    - lastTransitionTime: '2024-03-26T18:21:14Z'
      message: >-
        observe failed: cannot schedule a native provider during observe:
        0a3da036-5638-4963-942e-59d60616ee4c: cannot schedule native Terraform
        provider process: native provider reuse budget has been exceeded:
        invocationCount: 114, ttl: 100
      reason: ReconcileError
      status: 'False'
      type: Synced
    - lastTransitionTime: '2024-03-26T18:05:27Z'
      message: >-
        apply failed: Error creating AlertPolicy: googleapi: Error 400: Name
        must begin with
        'projects/{project_id}/notificationChannels/{channel_id}', got:
        my-sample-app-notification-email-channel:
      reason: ApplyFailure
      status: 'False'
      type: LastAsyncOperation
    - lastTransitionTime: '2024-03-26T18:11:29Z'
      reason: Finished
      status: 'True'
      type: AsyncOperation
spec:
  deletionPolicy: Delete
  forProvider:
    combiner: OR
    conditions:
      - conditionThreshold:
          - aggregations:
              - alignmentPeriod: 900s
                crossSeriesReducer: REDUCE_SUM
                perSeriesAligner: ALIGN_MEAN
            comparison: COMPARISON_GT
            duration: 900s
            filter: >-
              metric.type="prometheus.googleapis.com/kube_job_status_failed/gauge"
              AND resource.type="prometheus_target" AND
              resource.label.namespace=ka-dev-my-sample-app
            thresholdValue: 1
        displayName: my-sample-app job alert
    displayName: my-sample-app job alert policy
    enabled: true
    notificationChannels:
      - my-sample-app-notification-email-channel
  providerConfigRef:
    name: default

Steps to Reproduce

Create a GCP notificationChannel and then try to add it to the AlertPolicy

What happened?

The AlertPolicy is erroring out

Relevant Error Output Snippet

Error on the AlertPolicy

 apply failed: Error creating AlertPolicy: googleapi: Error 400: Name
        must begin with
        'projects/{project_id}/notificationChannels/{channel_id}', got:
        my-sample-app-notification-email-channel:


### Crossplane Version

https://github.com/upbound/universal-crossplane     "universal-crossplane": "1.11.3-up.1",

### Provider Version

xpkg.upbound.io/upbound/provider-gcp:v0.30.0

### Kubernetes Version

Client Version: v1.27.1 | Kustomize Version: v5.0.1 | Server Version: v1.26.11-gke.1055000

### Kubernetes Distribution

GKE

### Additional Info

_No response_
turkenf commented 6 months ago

Hi @avijitsarkar123,

Thank you for bringing up this issue. As I understand independent of the NotificationChannel resource, you could not create the AlertPolicy resource successfully.

As I see, you are using an old version of the monolithic provider. I could not reproduce the bug with the latest version. Could you please try with v1.0.2 and let us know?

And please take note: The monolithic package is deprecated in favor of the family resource packages and will no longer be maintained after 12 June 2024

github-actions[bot] commented 2 months ago

This provider repo does not have enough maintainers to address every issue. Since there has been no activity in the last 90 days it is now marked as stale. It will be closed in 14 days if no further activity occurs. Leaving a comment starting with /fresh will mark this issue as not stale.

github-actions[bot] commented 1 month ago

This issue is being closed since there has been no activity for 14 days since marking it as stale. If you still need help, feel free to comment or reopen the issue!

dhoeric-wu commented 1 month ago

@turkenf I can reproduce the same error with upbound/provider-gcp-monitoring:v1.8.0 and xpkg.upbound.io/upbound/provider-family-gcp:v1.8.0.

Could you suggest how to reference the notification channel from alert policy?

Resource MRs required to reproduce the bug

apiVersion: monitoring.gcp.upbound.io/v1beta1
kind: AlertPolicy
metadata:
  annotations:
    meta.upbound.io/example-id: monitoring/v1beta1/alertpolicy
  labels:
    testing.upbound.io/example-name: example_alert_policy
  name: example-alert-policy
spec:
  forProvider:
    combiner: OR
    conditions:
      - conditionThreshold:
          - aggregations:
              - alignmentPeriod: 60s
                perSeriesAligner: ALIGN_RATE
            comparison: COMPARISON_GT
            duration: 60s
            filter: metric.type="compute.googleapis.com/instance/disk/write_bytes_count" AND
              resource.type="gce_instance"
        displayName: test condition
    displayName: My Alert Policy
    notificationChannels:
      - example-notification-channel
    userLabels:
      foo: bar
---
apiVersion: monitoring.gcp.upbound.io/v1beta1
kind: NotificationChannel
metadata:
  annotations:
    meta.upbound.io/example-id: monitoring/v1beta1/notificationchannel
  labels:
    testing.upbound.io/example-name: example_notification_channel
  name: example-notification-channel
spec:
  forProvider:
    displayName: Test Notification Channel
    labels:
      email_address: fake_email@blahblah.com
    type: email