-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP Handle multiple compose versions #854
WIP Handle multiple compose versions #854
Conversation
cli/flags/common.go
Outdated
flags.SetAnnotation("namespace", "experimentalCLI", nil) | ||
flags.String("kubeconfig", "", "Kubernetes config file") | ||
flags.SetAnnotation("kubeconfig", "kubernetes", nil) | ||
flags.SetAnnotation("kubeconfig", "experimentalCLI", nil) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do these need to move to common? They aren't common to both orchestrators
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well I mostly need kubeconfig
(not namespace
) to be common, or at least available, for docker version
command, as you may specify different kubernetes configs and check the version against the pointed kubernetes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, but this flag isn't added to the version
command, so how is it going to be read?
Codecov Report
@@ Coverage Diff @@
## master #854 +/- ##
=========================================
- Coverage 53.26% 52.8% -0.46%
=========================================
Files 258 263 +5
Lines 16357 16702 +345
=========================================
+ Hits 8712 8820 +108
- Misses 7081 7316 +235
- Partials 564 566 +2 |
933a508
to
60106c6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a large PR, and it seems there are two logical changes here. 1) add kube version/stack api version to the API 2) update to include a new API version.
Could you split this into two separate PRs so it's easier to review?
) | ||
|
||
// GetAPIVersion returns the most recent stack API installed. | ||
func (c *KubeCli) GetAPIVersion() (StackVersion, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this should be a method on KubeCLI
. It only uses KubeConfig
, so it could be just a function which accepts a config and returns the version.
This should make it much easier to use from the version command.
I think it will also remove the need to export KubeConfig
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, I'll change this.
|
||
const ( | ||
// StackNotFound is returned when no stack api at all is detected on kubernetes. | ||
StackNotFound = "notFound" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be an error instead of a string? It looks like it's only used in the error case, so this const probably doesn't need to exist. Just use ""
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok! It was only to be consistent with the "enum" values. But "" is fine.
case findVersion(apiv1beta1.SchemeGroupVersion, groups.Groups): | ||
return StackAPIV1Beta1, nil | ||
default: | ||
return StackNotFound, fmt.Errorf("could not find %s api. Install it on your cluster first", apiv1beta1.SchemeGroupVersion.Group) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/fmt.Errorf/errors.Errorf/
(from pkg/errors
)
This prints the V1beta1 api version, which might be confusing if the user is expecting to use v2. Maybe it should just say "failed to find a Stack API version" or something like that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
cli/command/stack/kubernetes/cli.go
Outdated
case StackAPIV1Beta2: | ||
return c.newStackV1Beta2() | ||
default: | ||
return nil, fmt.Errorf("could not find matching Stack API version") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/fmt.Errorf/errors.New/
Maybe something like "No supported Stack API version" ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
cli/command/stack/kubernetes/cli.go
Outdated
kubeConfig *restclient.Config | ||
kubeNamespace string | ||
KubeConfig *restclient.Config | ||
KubeNamespace string | ||
} | ||
|
||
// WrapCli wraps command.Cli with kubernetes specifics | ||
func WrapCli(dockerCli command.Cli, cmd *cobra.Command) (*KubeCli, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of accepting a *cobra.Command
I think this should accept a
type Options struct {
Namespace string
Config string
}
the Options struct would be populated by flag parsing before calling WrapCli()
.
cobra.Command
is a huge struct and we don't use anything but a single method (.Flags()
), depending on the whole struct makes it harder to re-use (as we can see from the version command).
It should also make the code more obvious. Right now it's assumed that this will get the flag value, but in reality, when used with a different cmd
the flag is never presented to the user, so the flag will never be set.
cli/command/system/version.go
Outdated
@@ -75,12 +82,21 @@ type clientVersion struct { | |||
Orchestrator string `json:",omitempty"` | |||
} | |||
|
|||
type kubernetesVersion struct { | |||
Kubernetes string | |||
ComposeAPI string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
StackAPI
not ComposeAPI
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
cli/command/system/version.go
Outdated
} | ||
|
||
apiVersion, err := kli.GetAPIVersion() | ||
if err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this fails it should still attempt to get the kube version, so maybe this should be split into two functions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, done
cli/command/system/version.go
Outdated
return nil, nil | ||
} | ||
|
||
kli, err := kubernetes.WrapCli(dockerCli, cmd) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of WrapCLI()
if this could call a method that returns KubeConfig
then it can be used for both GetAPIVersion
and getting a kubeClient
without the need for KubeCli
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
cli/command/system/version.go
Outdated
@@ -109,7 +125,7 @@ func reformatDate(buildTime string) string { | |||
return buildTime | |||
} | |||
|
|||
func runVersion(dockerCli command.Cli, opts *versionOptions) error { | |||
func runVersion(dockerCli command.Cli, cmd *cobra.Command, opts *versionOptions) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should not be passing in cobra.Command
to the run functions. With the other suggestions (refactoring to remove the need to use KubeCli
to get version, and getting the kube config from a path string
arg instead of flags this shouldn't be necessary any more and can be reverted.
cli/command/stack/kubernetes/cli.go
Outdated
@@ -52,25 +51,27 @@ func WrapCli(dockerCli command.Cli, cmd *cobra.Command) (*KubeCli, error) { | |||
if err != nil { | |||
return nil, fmt.Errorf("Failed to load kubernetes configuration file '%s'", kubeConfig) | |||
} | |||
cli.kubeConfig = config | |||
cli.KubeConfig = config |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Related to other changes, this "get KubeConfig from flag or env" can be extracted into a function that just takes a single path string
argument.
@dnephin Let me just fix your comments before I split it into 2 PR? Otherwise they may "disappear". |
@@ -1,4 +0,0 @@ | |||
# Kubernetes client libraries |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should not remove that 👼
kubernetes/compose/v1beta1/scale.go
Outdated
yaml "gopkg.in/yaml.v2" | ||
) | ||
|
||
// Scale scale a service to the specified number of replicas |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
v1beta1 didn't support scale, it should still not support it (i.e. it comes in v1beta2).. so this should not be required
type Stack struct { | ||
StackImpl |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is required at all 🤔 (there shouldn't be any code change in v1beta1)
f14ed2f
to
68e09cb
Compare
…nent version in docker version command. Signed-off-by: Silvin Lubecki <[email protected]>
* Upgrade v1beta1 client to remove generated code Signed-off-by: Silvin Lubecki <[email protected]>
…use it kubernetes stack commands Signed-off-by: Silvin Lubecki <[email protected]>
Signed-off-by: Silvin Lubecki <[email protected]>
* Remove dependency from command in Kubernetes version checker Signed-off-by: Silvin Lubecki <[email protected]>
Signed-off-by: Silvin Lubecki <[email protected]>
* Refactor the internal stack model to use the v1beta2 stack model instead of compose type config Signed-off-by: Silvin Lubecki <[email protected]>
68e09cb
to
2e8f25d
Compare
Signed-off-by: Silvin Lubecki <[email protected]>
- What I did
A new compose component for Kubernetes version has been released (v1beta2), and I added support for both versions. I also added an
Orchestrator
section in thedocker version
command to log the compose component version and Kubernetes version we are working against.- How I did it
I put an interface on the compose client used by docker stack subcommands and added an implementation for each compose version.
- How to verify it
- Description for the changelog
- A picture of a cute animal (not mandatory but encouraged)
