Creating resource references

Creating resources that depend on others

A resource can depend upon other resources (for example, a firewall rule depends on a network, or a database runs on a particular instance). Config Connector defines these dependencies through resource references. This topic explains how to create resources with references.

Specifying resource references

You specify resource references in the resource's spec. The field's name is the resource's short name followed by Ref. For example:

  • The reference to a PubSubTopic named topic is topicRef.
  • The reference to a StorageBucket named bucket is bucketRef.

The reference is an object with a single field (name). The resource in resourceRef is replaced with the reference's name.

The YAML below describes a Cloud Pub/Sub PubSubSubscription that references a PubSubTopic named myTopic.

apiVersion: pubsub.cnrm.cloud.google.com/v1alpha2
kind: PubSubSubscription
metadata:
  name: pubsubsubscription-referencing-topic
spec:
  topicRef:
    name: myTopic

Cloud Pub/Sub Example

Create a PubSubTopic

In this example, you create a PubSubSubscription which depends on a PubSubTopic.

  1. Copy the following into a file named pubsub-topic.yaml, replacing [TOPIC_NAME] with your desired PubSubTopic name:
apiVersion: pubsub.cnrm.cloud.google.com/v1alpha2
kind: PubSubTopic
metadata:
  name: [TOPIC_NAME]

For example, the YAML to create a topic named myTopic is:

apiVersion: pubsub.cnrm.cloud.google.com/v1alpha2
kind: PubSubTopic
metadata:
  name: myTopic
  1. Create the PubSubTopic with the apply command, replacing [NAMESPACE_NAME] with your Namespace:
kubectl --namespace [NAMESPACE_NAME] apply -f pubsub-topic.yaml

Create a PubSubSubscription

  1. Copy the following into a file named pubsub-subscription.yaml, replacing [TOPIC_NAME] with the PubSubTopic name you used in step 1:
apiVersion: pubsub.cnrm.cloud.google.com/v1alpha2
kind: PubSubSubscription
metadata:
  name: pubsubsubscription-referencing-topic
spec:
  topicRef:
    name: [TOPIC_NAME]

For example, the YAML referencing the topic myTopic you created earlier is:

apiVersion: pubsub.cnrm.cloud.google.com/v1alpha2
kind: PubSubSubscription
metadata:
  name: pubsubsubscription-referencing-topic
spec:
  topicRef:
    name: myTopic
  1. Create the PubSubSubscription with kubectl apply, replacing [NAMESPACE_NAME] with the same Namespace name you used in step 2:
kubectl --namespace [NAMESPACE_NAME] apply -f pubsub-subscription.yaml 

Next Steps

Review the Resource reference to learn about the resources Config Connector supports.

هل كانت هذه الصفحة مفيدة؟ يرجى تقييم أدائنا:

إرسال تعليقات حول...

Config Connector Documentation