-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #898 from silvin-lubecki/add-stack-to-version-command
Print Stack API and Kubernetes versions in version command
- Loading branch information
Showing
11 changed files
with
242 additions
and
66 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 was deleted.
Oops, something went wrong.
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
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,50 @@ | ||
package kubernetes | ||
|
||
import ( | ||
apiv1beta1 "github.com/docker/cli/kubernetes/compose/v1beta1" | ||
"github.com/pkg/errors" | ||
apimachinerymetav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/runtime/schema" | ||
"k8s.io/client-go/kubernetes" | ||
) | ||
|
||
// StackVersion represents the detected Compose Component on Kubernetes side. | ||
type StackVersion string | ||
|
||
const ( | ||
// StackAPIV1Beta1 is returned if it's the most recent version available. | ||
StackAPIV1Beta1 = StackVersion("v1beta1") | ||
) | ||
|
||
// GetStackAPIVersion returns the most recent stack API installed. | ||
func GetStackAPIVersion(clientSet *kubernetes.Clientset) (StackVersion, error) { | ||
groups, err := clientSet.Discovery().ServerGroups() | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
return getAPIVersion(groups) | ||
} | ||
|
||
func getAPIVersion(groups *metav1.APIGroupList) (StackVersion, error) { | ||
switch { | ||
case findVersion(apiv1beta1.SchemeGroupVersion, groups.Groups): | ||
return StackAPIV1Beta1, nil | ||
default: | ||
return "", errors.Errorf("failed to find a Stack API version") | ||
} | ||
} | ||
|
||
func findVersion(stackAPI schema.GroupVersion, groups []apimachinerymetav1.APIGroup) bool { | ||
for _, group := range groups { | ||
if group.Name == stackAPI.Group { | ||
for _, version := range group.Versions { | ||
if version.Version == stackAPI.Version { | ||
return true | ||
} | ||
} | ||
} | ||
} | ||
return false | ||
} |
Oops, something went wrong.