Ressources
This commit is contained in:
84
src/helm/ressources.go
Normal file
84
src/helm/ressources.go
Normal file
@@ -0,0 +1,84 @@
|
||||
package helm
|
||||
|
||||
import (
|
||||
// "fmt"
|
||||
"encoding/json"
|
||||
)
|
||||
|
||||
type HelmStatus struct {
|
||||
Name string // Nom
|
||||
command HelmCommandInterface
|
||||
}
|
||||
|
||||
func (this *HelmStatus) New(bin string) {
|
||||
this.command = RealHelmCommandStatus{bin: bin}
|
||||
}
|
||||
|
||||
func (this *HelmStatus) NewMock(mock HelmCommandInterface) {
|
||||
this.command = mock
|
||||
}
|
||||
|
||||
////
|
||||
|
||||
type parseStatusInfoResourcesMetadata struct {
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
// type parseStatusInfoResourcesPod struct {
|
||||
// Api string `json:"apiVersion"`
|
||||
// }
|
||||
|
||||
type parseStatusInfoResourcesStatefulSet struct {
|
||||
Api string `json:"apiVersion"`
|
||||
Kind string `json:"kind"`
|
||||
Metadata parseStatusInfoResourcesMetadata `json:"metadata"`
|
||||
}
|
||||
|
||||
type parseStatusInfoResourcesDeployment struct {
|
||||
Api string `json:"apiVersion"`
|
||||
Kind string `json:"kind"`
|
||||
Metadata parseStatusInfoResourcesMetadata `json:"metadata"`
|
||||
}
|
||||
|
||||
type parseStatusInfoResources struct {
|
||||
// Pod []parseStatusInfoResourcesPod `json:"v1/Pod(related)"`
|
||||
StatefulSet []parseStatusInfoResourcesStatefulSet `json:"v1/StatefulSet"`
|
||||
Deployment []parseStatusInfoResourcesDeployment `json:"v1/Deployment"`
|
||||
}
|
||||
|
||||
type parseStatusInfo struct {
|
||||
Status string `json:"status"`
|
||||
Resources parseStatusInfoResources `json:"Resources"`
|
||||
}
|
||||
|
||||
|
||||
type parseStatus struct {
|
||||
Name string `json:"name"`
|
||||
Info parseStatusInfo `json:"info"`
|
||||
}
|
||||
|
||||
func (this HelmStatus) getRessources() (map[string]string, error) {
|
||||
|
||||
res := make(map[string]string)
|
||||
|
||||
status, err := this.command.Status(this.Name)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
|
||||
var objmap parseStatus
|
||||
|
||||
err = json.Unmarshal([]byte(status), &objmap)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
|
||||
for _, ele := range objmap.Info.Resources.StatefulSet {
|
||||
res[ele.Metadata.Name] = ele.Kind
|
||||
}
|
||||
for _, ele := range objmap.Info.Resources.Deployment {
|
||||
res[ele.Metadata.Name] = ele.Kind
|
||||
}
|
||||
|
||||
return res, nil
|
||||
}
|
Reference in New Issue
Block a user