Skip to content
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

compatible with k3d v5.x+ version #229

Merged
merged 5 commits into from
Oct 20, 2021

Conversation

shihaoH
Copy link
Member

@shihaoH shihaoH commented Oct 20, 2021

@LinuxSuRen LinuxSuRen changed the title compatible with k3d new version compatible with k3d v5.x+ version Oct 20, 2021
@LinuxSuRen LinuxSuRen added the enhancement New feature or request label Oct 20, 2021
@codecov
Copy link

codecov bot commented Oct 20, 2021

Codecov Report

❗ No coverage uploaded for pull request base (master@1767f34). Click here to learn what that means.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff            @@
##             master     #229   +/-   ##
=========================================
  Coverage          ?   10.43%           
=========================================
  Files             ?       33           
  Lines             ?     1447           
  Branches          ?        0           
=========================================
  Hits              ?      151           
  Misses            ?     1283           
  Partials          ?       13           
Flag Coverage Δ
unittests 10.43% <0.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.


Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1767f34...8043d0f. Read the comment docs.

Copy link
Contributor

@LinuxSuRen LinuxSuRen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job. I left some comments. Please take look at them.

@@ -119,6 +138,21 @@ func (o *k3dOption) runE(cmd *cobra.Command, args []string) (err error) {
return
}

//checkK3dVersion check if k3d version is greater than v5
func checkK3dVersion(version string) (bool, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's pretty easy to add unit tests for this function. So, I'd like to suggest you add it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about making the name of this function be more clear? Such as, isGreatThanV5 or isLargeThanV5.

It's hard to understand what checkK3dVersion will do by its name.

return err
}

b, err := checkK3dVersion(out)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use a meaningful variable name instead of b. It's hard to understand what b represents for.

@@ -3,4 +3,8 @@ package types
const (
// KsVersion is the latest release version
KsVersion = "v3.1.1"
// K3dVersion4 is the latest for k3d v4
K3dVersion4 = "v4.4.8"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there any other use cases for this const? Currently, I can see that it is only useful for the unit test.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No more for now, the version of k3d is obtained by local command, there is no place in our code to specify the version, whether to specify it as a constant

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, I'd prefer to remove these const. They are only test variables or data.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

Comment on lines 105 to 121
out, err := common.ExecCommandGetOutput("k3d", "version")
if err != nil {
return err
}

isNewVersion, err := checkK3dVersion(out)
if err != nil {
return err
}

// init agent port adaptation k3d v4
agentPort := "agent[0]"
// if k3d version is greater than v5, reset agent port
if isNewVersion {
agentPort = "agent:0"
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer to move these lines into a new function. But this comment does not bock other reviews.

Copy link
Contributor

@LinuxSuRen LinuxSuRen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check the CI status:

kubectl-plugin/install/k3d.go:144:9: if block ends with a return statement, so drop this else and outdent its block

Copy link
Contributor

@LinuxSuRen LinuxSuRen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent!

@LinuxSuRen LinuxSuRen merged commit 7522ed5 into kubesphere-sigs:master Oct 20, 2021
@shihaoH shihaoH deleted the k3dversioncompatible branch October 20, 2021 07:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

In k3d v5.0.0+ , not compatible
2 participants