This repository has been archived by the owner on Feb 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Cedric Kienzler
committed
Mar 17, 2021
1 parent
2142409
commit 1dc5a18
Showing
11 changed files
with
423 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/cedi/kkpctl/pkg/client" | ||
"github.com/cedi/kkpctl/pkg/describe" | ||
"github.com/kubermatic/go-kubermatic/models" | ||
"github.com/pkg/errors" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// clustersCmd represents the clusters command | ||
var describeNodeDeploymentCmd = &cobra.Command{ | ||
Use: "nodedeployment name", | ||
Short: "Describes a node deployment", | ||
Example: "kkpctl describe nodedeployment my_nodedeployment", | ||
Args: cobra.ExactArgs(1), | ||
ValidArgsFunction: getValidNodeDeploymentArgs, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
baseURL, apiToken := Config.GetCloudFromContext() | ||
kkp, err := client.NewClient(baseURL, apiToken) | ||
if err != nil { | ||
return errors.New("Could not initialize Kubermatic API client") | ||
} | ||
|
||
var cluster models.Cluster | ||
if datacenter == "" { | ||
cluster, err = kkp.GetClusterInProject(clusterID, projectID) | ||
} else if datacenter != "" && projectID != "" { | ||
cluster, err = kkp.GetClusterInProjectInDC(clusterID, projectID, datacenter) | ||
} | ||
|
||
if err != nil { | ||
return errors.Wrap(err, "could not fetch cluster") | ||
} | ||
|
||
nodeDeployment, err := kkp.GetNodeDeployment(args[0], cluster.ID, projectID, cluster.Spec.Cloud.DatacenterName) | ||
if err != nil { | ||
return errors.Wrap(err, "Error fetching node deployment") | ||
} | ||
|
||
nodeDeploymentNodes, err := kkp.GetNodeDeploymentNodes(nodeDeployment.ID, cluster.ID, projectID, cluster.Spec.Cloud.DatacenterName) | ||
if err != nil { | ||
return errors.Wrap(err, "Error fetching node deployment nodes") | ||
} | ||
|
||
nodeDeploymentEvents, err := kkp.GetNodeDeploymentEvents(nodeDeployment.ID, cluster.ID, projectID, cluster.Spec.Cloud.DatacenterName) | ||
if err != nil { | ||
return errors.Wrap(err, "Error fetching node deployment events") | ||
} | ||
|
||
meta := &describe.NodeDeploymentDescribeMeta{ | ||
NodeDeployment: &nodeDeployment, | ||
Nodes: nodeDeploymentNodes, | ||
NodeEvents: nodeDeploymentEvents, | ||
} | ||
|
||
parsed, err := describe.Object(meta) | ||
if err != nil { | ||
return errors.Wrap(err, "Error parsing datacenters") | ||
} | ||
|
||
fmt.Println(parsed) | ||
return nil | ||
}, | ||
} | ||
|
||
func init() { | ||
describeCmd.AddCommand(describeNodeDeploymentCmd) | ||
|
||
describeNodeDeploymentCmd.Flags().StringVarP(&clusterID, "cluster", "c", "", "ID of the cluster") | ||
describeNodeDeploymentCmd.MarkFlagRequired("cluster") | ||
describeNodeDeploymentCmd.RegisterFlagCompletionFunc("cluster", getValidClusterArgs) | ||
|
||
describeNodeDeploymentCmd.Flags().StringVarP(&projectID, "project", "p", "", "ID of the project") | ||
describeNodeDeploymentCmd.MarkFlagRequired("project") | ||
describeNodeDeploymentCmd.RegisterFlagCompletionFunc("project", getValidProjectArgs) | ||
|
||
describeNodeDeploymentCmd.Flags().StringVarP(&datacenter, "datacenter", "d", "", "Name of the datacenter") | ||
describeNodeDeploymentCmd.RegisterFlagCompletionFunc("datacenter", getValidDatacenterArgs) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package describe | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/cedi/kkpctl/pkg/output" | ||
"github.com/kubermatic/go-kubermatic/models" | ||
) | ||
|
||
// NodeDeploymentDescribeMeta contains all the necessary fields to describe a cluster | ||
type NodeDeploymentDescribeMeta struct { | ||
NodeDeployment *models.NodeDeployment | ||
Nodes []models.Node | ||
NodeEvents []models.Event | ||
} | ||
|
||
// describeProject takes any KKP Cluster and describes it | ||
func describeNodeDeployment(meta *NodeDeploymentDescribeMeta) (string, error) { | ||
nd := meta.NodeDeployment | ||
evnt := meta.NodeEvents | ||
nodes := meta.Nodes | ||
|
||
nodeDeploymentTable, err := output.ParseOutput(nd, output.Text, output.Name) | ||
if err != nil || len(nodeDeploymentTable) == 0 { | ||
return "", err | ||
} | ||
|
||
nodeTable, err := output.ParseOutput(nodes, output.Text, output.Name) | ||
if err != nil || len(nodeTable) == 0 { | ||
return "", err | ||
} | ||
|
||
nodeTaintsTable, err := output.ParseOutput(nd.Spec.Template.Taints, output.Text, output.Name) | ||
if err != nil || len(nodeTaintsTable) == 0 { | ||
nodeTaintsTable = "[None]" | ||
} | ||
|
||
nodeEventTable, err := output.ParseOutput(evnt, output.Text, output.Name) | ||
if err != nil || len(nodeEventTable) == 0 { | ||
nodeEventTable = "[None]" | ||
} | ||
|
||
labels := make([]string, 0) | ||
for key, value := range nd.Spec.Template.Labels { | ||
labels = append(labels, fmt.Sprintf("%s=%s", key, value)) | ||
} | ||
if len(labels) == 0 { | ||
labels = append(labels, "[None]") | ||
} | ||
|
||
result := fmt.Sprintf(`Node Deployment: | ||
%s | ||
Nodes: | ||
%s | ||
Taints: | ||
%s | ||
Labels: | ||
%s | ||
Events: | ||
%s`, | ||
nodeDeploymentTable, | ||
nodeTable, | ||
nodeTaintsTable, | ||
strings.Join(labels, "; "), | ||
nodeEventTable, | ||
) | ||
|
||
return result, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.