<p>My probelm is that i am trying to use the <code>unstructured.Unstructured</code> type to create a deployment as such:</p>

<pre><code>// +kubebuilder:rbac:groups=stable.resource.operator.io,resources=resource,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=stable.resource.operator.io,resources=resource/status,verbs=get;update;patch
// +kubebuilder:rbac:groups=apps,resources=deployments,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=apps,resources=deployments/status,verbs=get;list;watch;create;update;patch;delete
func (r *ResourceReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {

    ctx := context.Background()
    log := r.Log.WithValues("resource", req.NamespacedName)
    instance := &amp;stablev1.Resource{}
    // your logic here

    if err := r.Get(ctx, req.NamespacedName, instance); err != nil {
        log.Error(err, "unable to fetch Resource")
        // we'll ignore not-found errors, since they can't be fixed by an immediate
        // requeue (we'll need to wait for a new notification), and we can get them
        // on deleted requests.
        return ctrl.Result{}, ignoreNotFound(err)
    }
    // your logic here
    u := &amp;unstructured.Unstructured{}
    u.Object = map[string]interface{}{
        "name":      "name",
        "namespace": "namespace",
        "spec": map[string]interface{}{
            "replicas": 2,
            "selector": map[string]interface{}{
                "matchLabels": map[string]interface{}{
                    "foo": "bar",
                },
            },
            "template": map[string]interface{}{
                "labels": map[string]interface{}{
                    "foo": "bar",
                },
                "spec": map[string]interface{}{
                    "containers": []map[string]interface{}{
                        {
                            "name":  "nginx",
                            "image": "nginx",
                        },
                    },
                },
            },
        },
    }
    u.SetGroupVersionKind(schema.GroupVersionKind{
        Group:   "apps",
        Kind:    "Deployment",
        Version: "v1",
    })
    err = r.Create(context.Background(), u)
    log.Error(err, "unable to get object")
    log.V(1).Info("reconciling")
    return ctrl.Result{}, nil

}
</code></pre>

<p>My understanding is that I have specified the rbac rules, my operator should be able to create said Deployment, but I am still getting the error:</p>

<pre><code>the server does not allow this method on the requested resource
</code></pre>

<p>All the examples I have seen are based of using the actual deployment type, I cant find anywhere where there is an example of doing this with type unstructured, am i missing something?
Just to save time, I have tried:</p>

<ul>
<li>Applying the clusterroles manually</li>
<li>Given the operator cluster-admin</li>
<li>used both make run and make deploy (obviously after running make manifests etc..)</li>
<li>The roles generator is working</li>
<li>I have started a new project to make sure me playing around with env is not the cause</li>
</ul>

<p>So seperatley from what the docs stated at <a href="https://godoc.org/sigs.k8s.io/controller-runtime/pkg/client" rel="nofollow noreferrer">https://godoc.org/sigs.k8s.io/controller-runtime/pkg/client</a> when you define the type unstructured.Unstructured you need to set the namespace and name in the metadata field as such:</p>

<pre><code>u.Object = map[string]interface{}{
        "metadata": map[string]interface{}{
            "name":      "name",
            "namespace": "namespace"},
        "spec": map[string]interface{}{
            "replicas": 2,
            "selector": map[string]interface{}{
                "matchLabels": map[string]interface{}{
                    "foo": "bar",
                },
            },
            "template": map[string]interface{}{
                "labels": map[string]interface{}{
                    "foo": "bar",
                },
                "spec": map[string]interface{}{
                    "containers": []map[string]interface{}{
                        {
                            "name":  "nginx",
                            "image": "nginx",
                        },
                    },
                },
            },
        },
    }
</code></pre>

<p>otherwise unstructured client reads it as cluster scoped resource deployments, which does not exist</p>
