vmware-archive / operator-builder

A Kubebuilder plugin to accelerate the development of Kubernetes operators
MIT License
41 stars 6 forks source link

bug: resource markers inoperable #256

Closed scottd018 closed 2 years ago

scottd018 commented 2 years ago

UPDATE: this ended up being user error. Was not using the latest version via make build; make install. However, there was an associated problem with this, and that was when a field is not defined in the manifest which requests it, there would be a panic in that the resource marker could not be associated with its respective field. This was fixed in PR #263 .

This manifest:

---
# +operator-builder:resource:collectionField=environment,value="sandbox",include
apiVersion: v1
kind: ServiceAccount
metadata:
  name: csi-secrets-store-provider-aws
  namespace: kube-system

Results in this code:

// CreateServiceAccountKubeSystemCsiSecretsStoreProviderAws creates the csi-secrets-store-provider-aws ServiceAccount resource.
func CreateServiceAccountKubeSystemCsiSecretsStoreProviderAws(
    parent *ws1v1alpha1.SaaSWatchPlatform,
    collection *ws1v1alpha1.SaaSWatchCollection,
) ([]client.Object, error) {
    resourceObjs := []client.Object{}
    var resourceObj = &unstructured.Unstructured{
        Object: map[string]interface{}{
            // +operator-builder:resource:collectionField=environment,value="sandbox",include
            "apiVersion": "v1",
            "kind":       "ServiceAccount",
            "metadata": map[string]interface{}{
                "name":      "csi-secrets-store-provider-aws",
                "namespace": "kube-system",
            },
        },
    }

    resourceObjs = append(resourceObjs, resourceObj)

    return resourceObjs, nil
}

It should include logic that scaffolds the code which will exclude when the condition is met.