Skip to content

Commit

Permalink
better sealos version (#2679)
Browse files Browse the repository at this point in the history
  • Loading branch information
cdjianghan authored Feb 27, 2023
1 parent d073a0e commit 0890a0a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 15 deletions.
42 changes: 28 additions & 14 deletions cmd/sealos/cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,43 @@ func getContact() string {
}

func PrintInfo() error {
var (
marshalled []byte
)
OutputInfo := &version.Output{}
OutputInfo.SealosVersion = version.Get()
cluster, err := clusterfile.GetClusterFromName(clusterName)
if err != nil {
logger.Debug(err, "fail to find cluster from name")
err = PrintToStd(OutputInfo)
if err != nil {
return err
}
return nil
}
OutputInfo.KubernetesVersion = version.GetKubernetesVersion(cluster)
OutputInfo.CriRuntimeVersion = version.GetCriRuntimeVersion()

err = PrintToStd(OutputInfo)
if err != nil {
return err
}
missinfo := []string{}
if OutputInfo.KubernetesVersion == nil {
missinfo = append(missinfo, "kubernetes version")
}
if OutputInfo.CriRuntimeVersion == nil {
missinfo = append(missinfo, "cri runtime version")
}
if OutputInfo.KubernetesVersion == nil || OutputInfo.CriRuntimeVersion == nil {
fmt.Printf("WARNING: Failed to get %s.\nCheck kubernetes status or use command \"sealos run\" to launch kubernetes\n", strings.Join(missinfo, " and "))
}

return nil
}

func PrintToStd(OutputInfo *version.Output) error {
var (
marshalled []byte
err error
)
switch output {
case "yaml":
marshalled, err = yaml.Marshal(&OutputInfo)
Expand All @@ -98,16 +123,5 @@ func PrintInfo() error {
// However, we follow a policy of never panicking.
return fmt.Errorf("versionOptions were not validated: --output=%q should have been rejected", output)
}
missinfo := []string{}
if OutputInfo.KubernetesVersion == nil {
missinfo = append(missinfo, "kubernetes version")
}
if OutputInfo.CriRuntimeVersion == nil {
missinfo = append(missinfo, "cri runtime version")
}
if OutputInfo.KubernetesVersion == nil || OutputInfo.CriRuntimeVersion == nil {
fmt.Printf("WARNING: Failed to get %s.\nCheck kubernetes status or use command \"sealos run\" to launch kubernetes\n", strings.Join(missinfo, " and "))
}

return nil
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ require (
k8s.io/kubernetes v1.25.6
k8s.io/utils v0.0.0-20220728103510-ee6ede2d64ed
sigs.k8s.io/controller-runtime v0.13.0
sigs.k8s.io/kustomize/kyaml v0.13.9
sigs.k8s.io/yaml v1.3.0
)

Expand Down Expand Up @@ -213,7 +214,6 @@ require (
oras.land/oras-go v1.2.0 // indirect
sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2 // indirect
sigs.k8s.io/kustomize/api v0.12.1 // indirect
sigs.k8s.io/kustomize/kyaml v0.13.9 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
)

Expand Down

0 comments on commit 0890a0a

Please sign in to comment.