fix: Simplify class lookup. Always use list with filtering, no get
@@ -166,21 +166,13 @@ func ClassLookup(kubeClient *kubernetes.Cluster, serviceClassName string) (*Serv
return nil, err
}
- serviceClass, err := dynamicClient.Resource(serviceClassGVR).
- Get(context.Background(), serviceClassName, metav1.GetOptions{})
- if err != nil {
- if apierrors.IsNotFound(err) {
- // We are not done yet. Not having found the
- // class with that name we may find it through
- // its external name. While for minibroker the
- // two are same, for the google broker the
- // regular name is an unfriendly hash/uuid,
- // while the external-name is friendly.
+ // We always list and then filter for the external name of the
+ // class. See `ListClasses` above on why.
//
- // Nothing in the labels for easy filtering by
- // kube, so it is done here in code. Like
- // `ServiceClassMatching` (pass/client.go),
- // just for exact match.
+ // Note that there are no labels enabling easy filtering by
+ // kube itself, so it is done here in code. Like
+ // `ServiceClassMatching` (pass/client.go), just for exact
+ // match.
serviceClasses, err := dynamicClient.Resource(serviceClassGVR).
List(context.Background(),
@@ -216,31 +208,8 @@ func ClassLookup(kubeClient *kubernetes.Cluster, serviceClassName string) (*Serv
}, nil
}
- // Not found via external-name either. Giving up.
+ // Not found
return nil, nil
- } else {
- return nil, err
- }
- }
-
- spec := serviceClass.Object["spec"].(map[string]interface{})
-
- externalName := spec["externalName"].(string)
- description := spec["description"].(string)
- clusterServiceBrokerName := spec["clusterServiceBrokerName"].(string)
-
- metadata := serviceClass.Object["metadata"].(map[string]interface{})
-
- labels := metadata["labels"].(map[string]interface{})
- hash := labels["servicecatalog.k8s.io/spec.externalID"].(string)
-
- return &ServiceClass{
- Name: externalName,
- Broker: clusterServiceBrokerName,
- Description: description,
- Hash: hash,
- kubeClient: kubeClient,
- }, nil
}
// CatalogServiceList returns a ServiceList of all available catalog Services
