diff options
-rw-r--r-- | src/k8splugin/api/queryhandler.go | 2 | ||||
-rw-r--r-- | src/k8splugin/internal/app/client.go | 1 | ||||
-rw-r--r-- | src/k8splugin/internal/app/instance.go | 44 | ||||
-rw-r--r-- | src/k8splugin/internal/app/query.go | 6 | ||||
-rw-r--r-- | src/k8splugin/internal/rb/profile.go | 16 |
5 files changed, 55 insertions, 14 deletions
diff --git a/src/k8splugin/api/queryhandler.go b/src/k8splugin/api/queryhandler.go index 9c11954c..f5950cdf 100644 --- a/src/k8splugin/api/queryhandler.go +++ b/src/k8splugin/api/queryhandler.go @@ -52,7 +52,7 @@ func (i queryHandler) queryHandler(w http.ResponseWriter, r *http.Request) { return } // instance id is irrelevant here - resp, err := i.client.Query(namespace, cloudRegion, apiVersion, kind, name, labels, "query") + resp, err := i.client.Query(namespace, cloudRegion, apiVersion, kind, name, labels) if err != nil { log.Error("Error getting Query results", log.Fields{ "error": err, diff --git a/src/k8splugin/internal/app/client.go b/src/k8splugin/internal/app/client.go index f70dc0a5..a2868cd5 100644 --- a/src/k8splugin/internal/app/client.go +++ b/src/k8splugin/internal/app/client.go @@ -256,6 +256,7 @@ func (k *KubernetesClient) queryResources(apiVersion, kind, labelSelector, names LabelSelector: labelSelector, } var unstrList *unstructured.UnstructuredList + dynClient.Resource(gvr).Namespace(namespace).List(context.TODO(), opts) switch mapping.Scope.Name() { case meta.RESTScopeNameNamespace: unstrList, err = dynClient.Resource(gvr).Namespace(namespace).List(context.TODO(), opts) diff --git a/src/k8splugin/internal/app/instance.go b/src/k8splugin/internal/app/instance.go index c4cce5ed..e50a59e5 100644 --- a/src/k8splugin/internal/app/instance.go +++ b/src/k8splugin/internal/app/instance.go @@ -34,6 +34,7 @@ import ( "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/cli-runtime/pkg/resource" + "github.com/onap/multicloud-k8s/src/k8splugin/internal/config" "github.com/onap/multicloud-k8s/src/k8splugin/internal/db" "github.com/onap/multicloud-k8s/src/k8splugin/internal/helm" "github.com/onap/multicloud-k8s/src/k8splugin/internal/namegenerator" @@ -461,7 +462,15 @@ func (v *InstanceClient) Query(id, apiVersion, kind, name, labels string) (Insta return InstanceStatus{}, pkgerrors.Wrap(err, "Unmarshaling Instance Value") } - resources, err := queryClient.Query(resResp.Namespace, resResp.Request.CloudRegion, apiVersion, kind, name, labels, id) + if labels == "" || strings.Contains(strings.ToLower(labels), config.GetConfiguration().KubernetesLabelName) == false { + labelValue := config.GetConfiguration().KubernetesLabelName + "=" + id + if labels != "" { + labels = labels + "," + } + labels = labels + labelValue + } + + resources, err := queryClient.Query(resResp.Namespace, resResp.Request.CloudRegion, apiVersion, kind, name, labels) if err != nil { return InstanceStatus{}, pkgerrors.Wrap(err, "Querying Resources") } @@ -502,6 +511,11 @@ func (v *InstanceClient) Status(id string) (InstanceStatus, error) { if err != nil { return InstanceStatus{}, pkgerrors.Wrap(err, "Getting CloudRegion Information") } + req := resResp.Request + profile, err := rb.NewProfileClient().Get(req.RBName, req.RBVersion, req.ProfileName) + if err != nil { + return InstanceStatus{}, pkgerrors.New("Unable to find Profile instance status") + } cumulatedErrorMsg := make([]string, 0) podsStatus, err := k8sClient.getPodsByLabel(resResp.Namespace) @@ -534,12 +548,36 @@ Main: } } } + generalStatus = append(generalStatus, podsStatus...) + + if profile.ExtraResourceTypes != nil && len(profile.ExtraResourceTypes) > 0 { + queryClient := NewQueryClient() + labelValue := config.GetConfiguration().KubernetesLabelName + "=" + id + for _, extraType := range profile.ExtraResourceTypes { + queryStatus, err := queryClient.Query(resResp.Namespace, resResp.Request.CloudRegion, extraType.GroupVersion().Identifier(), extraType.Kind, "", labelValue) + if err != nil { + return InstanceStatus{}, pkgerrors.Wrap(err, "Querying Resources") + } + for _, rs := range queryStatus.ResourcesStatus { + foundRes := false + for _, res := range generalStatus { + if res.GVK == rs.GVK && res.Name == rs.Name { + foundRes = true + break + } + } + if !foundRes { + generalStatus = append(generalStatus, rs) + } + } + } + } //We still need to iterate through rss list even the status is not DONE, to gather status of rss + pod for the response resp := InstanceStatus{ Request: resResp.Request, - ResourceCount: int32(len(generalStatus) + len(podsStatus)), + ResourceCount: int32(len(generalStatus)), Ready: isReady && resResp.Status == "DONE", - ResourcesStatus: append(generalStatus, podsStatus...), + ResourcesStatus: generalStatus, } if len(cumulatedErrorMsg) != 0 { diff --git a/src/k8splugin/internal/app/query.go b/src/k8splugin/internal/app/query.go index cb645afd..251b14e6 100644 --- a/src/k8splugin/internal/app/query.go +++ b/src/k8splugin/internal/app/query.go @@ -33,7 +33,7 @@ type QueryStatus struct { // QueryManager is an interface exposes the instantiation functionality type QueryManager interface { - Query(namespace, cloudRegion, apiVersion, kind, name, labels, id string) (QueryStatus, error) + Query(namespace, cloudRegion, apiVersion, kind, name, labels string) (QueryStatus, error) } // QueryClient implements the InstanceManager interface @@ -53,12 +53,12 @@ func NewQueryClient() *QueryClient { } // Query returns state of instance's filtered resources -func (v *QueryClient) Query(namespace, cloudRegion, apiVersion, kind, name, labels, id string) (QueryStatus, error) { +func (v *QueryClient) Query(namespace, cloudRegion, apiVersion, kind, name, labels string) (QueryStatus, error) { //Read the status from the DD k8sClient := KubernetesClient{} - err := k8sClient.Init(cloudRegion, id) + err := k8sClient.Init(cloudRegion, "dummy") //we don't care about instance id in this request if err != nil { return QueryStatus{}, pkgerrors.Wrap(err, "Getting CloudRegion Information") } diff --git a/src/k8splugin/internal/rb/profile.go b/src/k8splugin/internal/rb/profile.go index f9ac56bd..78023e59 100644 --- a/src/k8splugin/internal/rb/profile.go +++ b/src/k8splugin/internal/rb/profile.go @@ -26,6 +26,7 @@ import ( "github.com/onap/multicloud-k8s/src/k8splugin/internal/db" "github.com/onap/multicloud-k8s/src/k8splugin/internal/helm" + "k8s.io/apimachinery/pkg/runtime/schema" pkgerrors "github.com/pkg/errors" ) @@ -33,13 +34,14 @@ import ( // Profile contains the parameters needed for resource bundle (rb) profiles // It implements the interface for managing the profiles type Profile struct { - RBName string `json:"rb-name"` - RBVersion string `json:"rb-version"` - ProfileName string `json:"profile-name"` - ReleaseName string `json:"release-name"` - Namespace string `json:"namespace"` - KubernetesVersion string `json:"kubernetes-version"` - Labels map[string]string `json:"labels"` + RBName string `json:"rb-name"` + RBVersion string `json:"rb-version"` + ProfileName string `json:"profile-name"` + ReleaseName string `json:"release-name"` + Namespace string `json:"namespace"` + KubernetesVersion string `json:"kubernetes-version"` + Labels map[string]string `json:"labels"` + ExtraResourceTypes []schema.GroupVersionKind `json:"extra-resource-types"` } // ProfileManager is an interface exposes the resource bundle profile functionality |