## Fetch postgres credentials from the cluster where services are deployed. ## Create a Secret in the management cluster that contains the credentials ## Secret is named pg-credentials and it is created in the same namespace of the managed cluster apiVersion: lib.projectsveltos.io/v1beta1 kind: EventSource metadata: name: detect-credentials-secret spec: collectResources: true resourceSelectors: - group: "" version: "v1" kind: "Secret" labelFilters: - key: cnpg.io/reload operation: Equal value: "true" --- apiVersion: lib.projectsveltos.io/v1beta1 kind: EventTrigger metadata: name: credentials-secret spec: sourceClusterSelector: matchLabels: type: services destinationClusterSelector: matchLabels: type: mgmt eventSourceName: detect-credentials-secret oneForEvent: true policyRefs: - name: credentials namespace: default kind: Secret --- apiVersion: v1 kind: Secret metadata: name: credentials namespace: default annotations: projectsveltos.io/instantiate: ok type: addons.projectsveltos.io/cluster-profile stringData: credentials: | apiVersion: v1 kind: Secret metadata: name: pg-credentials namespace: {{ .Resource.metadata.namespace }} data: "password": "{{ get .Resource.data `password` }}" "user": "{{ get .Resource.data `username` }}" --- ## Fetch postgres loadbalancer external-ip:port from the cluster where services are deployed. ## Create a ConfigMap in the management cluster that contains those info ## ConfigMap is named pg-loadbalancer-data and it is created in the same namespace of the managed cluster apiVersion: lib.projectsveltos.io/v1beta1 kind: EventSource metadata: name: detect-loadbalancer spec: collectResources: true resourceSelectors: - group: "" version: "v1" kind: "Service" labelFilters: - key: cnpg.io/isManaged operation: Equal value: "true" --- apiVersion: lib.projectsveltos.io/v1beta1 kind: EventTrigger metadata: name: cnpg-loadbalancer-data spec: sourceClusterSelector: matchLabels: type: services destinationClusterSelector: matchLabels: type: mgmt eventSourceName: detect-loadbalancer oneForEvent: true policyRefs: - name: loadbalancer-data namespace: default kind: ConfigMap --- apiVersion: v1 kind: ConfigMap metadata: name: loadbalancer-data namespace: default annotations: projectsveltos.io/instantiate: ok data: credentials: | apiVersion: v1 kind: ConfigMap metadata: name: pg-loadbalancer-data namespace: {{ .Resource.metadata.namespace }} data: external-ip: {{ (index .Resource.status.loadBalancer.ingress 0).ip }} port: "{{ (index .Resource.spec.ports 0).targetPort }}"