Skip to content

Commit

Permalink
Merge pull request #54 from cloud-ark/add-support-for-statefulsets
Browse files Browse the repository at this point in the history
Added resourceDetails endpoint
  • Loading branch information
devdattakulkarni authored Aug 7, 2019
2 parents 97117e0 + 3ea9609 commit f64cdc2
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
17 changes: 17 additions & 0 deletions pkg/apiserver/apiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,22 @@ func (c completedConfig) New() (*DiscoveryServer, error) {
return s, nil
}

func handleResourceDetailsEndpoint(request *restful.Request, response *restful.Response) {

resourceKind := request.QueryParameter(KIND_QUERY_PARAM)
resourceInstance := request.QueryParameter(INSTANCE_QUERY_PARAM)
namespace := request.QueryParameter(NAMESPACE_QUERY_PARAM)

fmt.Printf("Kind:%s, Instance:%s\n", resourceKind, resourceInstance)
if namespace == "" {
namespace = "default"
}
resourceInfo := discovery.TotalClusterCompositions.QueryResource(resourceKind, resourceInstance, namespace)
fmt.Printf("Resource Info:%v\n", resourceInfo)

response.Write([]byte(resourceInfo))
}

func installKubePlusPaths(discoveryServer *DiscoveryServer) {

path := "/apis/" + GroupName + "/" + GroupVersion
Expand All @@ -140,6 +156,7 @@ func installKubePlusPaths(discoveryServer *DiscoveryServer) {
//ws1.Route(ws1.GET("/implementation_details").To(handleImplementationDetailsEndpoint))
//ws1.Route(ws1.GET("/usage").To(handleUsageEndpoint))
ws1.Route(ws1.GET("/man").To(handleManPageEndpoint))
ws1.Route(ws1.GET("/resourceDetails").To(handleResourceDetailsEndpoint))

discoveryServer.GenericAPIServer.Handler.GoRestfulContainer.Add(ws1)
}
Expand Down
20 changes: 17 additions & 3 deletions pkg/discovery/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ func getResourceKinds() []string {
func getResourceNames(resourceKind, namespace string) []MetaDataAndOwnerReferences {
resourceApiVersion := kindVersionMap[resourceKind]
resourceKindPlural := KindPluralMap[resourceKind]
content := queryAPIServer(resourceApiVersion, resourceKindPlural, namespace)
content := queryResources(resourceApiVersion, resourceKindPlural, namespace)
metaDataAndOwnerReferenceList := parseMetaData(content)
return metaDataAndOwnerReferenceList
}
Expand Down Expand Up @@ -426,7 +426,7 @@ func buildCompositions(parentResourceKind string, parentResourceName string, par
childResourceApiVersion := kindVersionMap[childResourceKind]
var content []byte
var metaDataAndOwnerReferenceList []MetaDataAndOwnerReferences
content = queryAPIServer(childResourceApiVersion, childKindPlural, parentNamespace)
content = queryResources(childResourceApiVersion, childKindPlural, parentNamespace)
metaDataAndOwnerReferenceList = parseMetaData(content)

childrenList := filterChildren(&metaDataAndOwnerReferenceList, parentResourceName)
Expand Down Expand Up @@ -484,14 +484,28 @@ func getAllNamespaces() []string {
return parseNamespacesResponse(resp_body)
}

func queryAPIServer(resourceApiVersion, resourcePlural, namespace string) []byte {
func (cp *ClusterCompositions) QueryResource(resourceKind, resourceName, namespace string) []byte {
resourceApiVersion := kindVersionMap[resourceKind]
resourceKindPlural := KindPluralMap[resourceKind]
url1 := fmt.Sprintf("https://%s:%s/%s/namespaces/%s/%s/%s", serviceHost, servicePort, resourceApiVersion, namespace, resourceKindPlural, resourceName)
fmt.Printf("Resource Query URL:%s\n", url1)
contents := queryAPIServer(url1)
return contents
}

func queryResources(resourceApiVersion, resourcePlural, namespace string) []byte {
var url1 string
if !strings.Contains(resourceApiVersion, resourcePlural) {
url1 = fmt.Sprintf("https://%s:%s/%s/namespaces/%s/%s", serviceHost, servicePort, resourceApiVersion, namespace, resourcePlural)
} else {
url1 = fmt.Sprintf("https://%s:%s/%s", serviceHost, servicePort, resourceApiVersion)
}
//fmt.Printf("Url:%s\n",url1)
contents := queryAPIServer(url1)
return contents
}

func queryAPIServer(url1 string) []byte {
caToken := getToken()
caCertPool := getCACert()
u, err := url.Parse(url1)
Expand Down

0 comments on commit f64cdc2

Please sign in to comment.