<p>What is the best method for checking to see if a custom resource definition exists before running a script, using only <code>kubectl</code> command line?</p>

<p>We have a yaml file that contains definitions for a NATS cluster <code>ServiceAccount</code>, <code>Role</code>, <code>ClusterRoleBinding</code> and <code>Deployment</code>. The image used in the <code>Deployment</code> creates the <code>crd</code>, and the second script uses that <code>crd</code> to deploy a set of <code>pods</code>. At the moment our CI pipeline needs to run the second script a few times, only completing successfully once the <code>crd</code> has been fully created. I've tried to use <code>kubectl wait</code> but cannot figure out what condition to use that applies to the completion of a <code>crd</code>. </p>

<p>Below is my most recent, albeit completely wrong, attempt, however this illustrates the general sequence we'd like. </p>

<p><code>kubectl wait --for=condition=complete kubectl apply -f 1.nats-cluster-operator.yaml kubectl apply -f 2.nats-cluster.yaml</code></p>

NealR
<p>The condition for a CRD would be <code>established</code>:</p>

<pre><code>kubectl -n &lt;namespace-here&gt; wait --for condition=established --timeout=60s crd/&lt;crd-name-here&gt;
</code></pre>

<p>You may want to adjust <code>--timeout</code> appropriately.</p>
