Skip to content

kmeshctl install #978

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

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open

kmeshctl install #978

wants to merge 12 commits into from

Conversation

thebigbone
Copy link

What type of PR is this?

/kind feature

What this PR does / why we need it:

adds install command for kmeshctl which will install all the resources for kmesh in a k8s cluster

Which issue(s) this PR fixes:
Fixes #552

Does this PR introduce a user-facing change?:

NONE

@kmesh-bot
Copy link
Collaborator

Welcome @thebigbone! It looks like this is your first PR to kmesh-net/kmesh 🎉

ctl/main.go Outdated
@@ -43,6 +44,7 @@ func main() {
rootCmd.AddCommand(waypoint.NewCmd())
rootCmd.AddCommand(version.NewCmd())
rootCmd.AddCommand(accesslog.NewCmd())
rootCmd.AddCommand(install.NewCmd())
Copy link
Member

Choose a reason for hiding this comment

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

Also need to update doc when this PR get merged.

log.Fatal(err)
}

kubeconfig := os.Getenv("HOME") + "/.kube/config"
Copy link
Member

Choose a reason for hiding this comment

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

Use existing (tools)[https://github.com/kmesh-net/kmesh/blob/main/ctl/utils/utils.go#L31] to create k8s client direclty which has built-in method for applying yaml files.

Copy link
Author

Choose a reason for hiding this comment

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

So, I should remove the custom doServerSideApply function?

Copy link
Member

Choose a reason for hiding this comment

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

I think you could.

@@ -0,0 +1,167 @@
package install
Copy link
Member

Choose a reason for hiding this comment

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

Add copyright

"log"
"os"

"k8s.io/apimachinery/pkg/api/meta"
Copy link
Member

Choose a reason for hiding this comment

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

Arrange the dependency order, put the standard lib together, put Kmesh lib together and put third-party dependencies together.

func NewCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "install",
Short: "install kmesh with all the resources",
Copy link
Member

Choose a reason for hiding this comment

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

Add examples, refer to other subcommands.

panic(err.Error())
}

resources := []Resource{
Copy link
Member

Choose a reason for hiding this comment

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

Why not just apply all files in the yaml diretory instead of listing each files which may change in the future?

Copy link
Author

Choose a reason for hiding this comment

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

How would that work?

Copy link
Member

Choose a reason for hiding this comment

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

You could get all yaml contents and call this function

Copy link
Member

Choose a reason for hiding this comment

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

I don't know if there is an elegant way to direclty get the contents of all files under yaml directory or to know which files are in this directory and download them one by one.

Copy link
Author

Choose a reason for hiding this comment

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

I don't know if there is an elegant way to direclty get the contents of all files under yaml directory or to know which files are in this directory and download them one by one.

curl -s "https://api.github.com/repos/kmesh-net/kmesh/contents/deploy/yaml" | jq -r '.[] | .download_url'

Copy link
Author

Choose a reason for hiding this comment

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

The ApplyYAMLContents function works fine but it requires namespace argument. For now, I can separate the kmesh-system and istio but it can break in the future because there could be a new yaml file with a different namespace.

Copy link
Member

Choose a reason for hiding this comment

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

I think you could specify namespace as "", so that it will direcly use the ns specified in yaml.

Copy link
Author

Choose a reason for hiding this comment

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

Oh, that's helpful. I was parsing the namespace field in every file.

{Name: "serviceAccount", URL: getURL(version, "serviceaccount.yaml")},
}

fmt.Println("using version: ", version)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit:install kmesh version:

Copy link

codecov bot commented Oct 24, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 48.46%. Comparing base (8c72e4c) to head (1e39cec).
Report is 168 commits behind head on main.

see 35 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

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

# Install a specific version of kmesh
kmeshctl install --version 0.5`,
Run: func(cmd *cobra.Command, args []string) {
version, err := cmd.Flags().GetString("version")
Copy link
Contributor

Choose a reason for hiding this comment

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

We still have issue #949.
@YaoZengzeng Has this problem been fixed?

Copy link
Member

Choose a reason for hiding this comment

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

No, I hope this issue could be fixed with the solution of #892, but it seems that this problem is not being addressed now. If no one has dealt it by then, I will fix it.


deployYaml, err := io.ReadAll(resp.Body)
if err != nil {
log.Fatalf("yamlFile.Get err #%v ", err)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
log.Fatalf("yamlFile.Get err #%v ", err)
log.Fatalf("yamlFile.Get err: %v ", err)

func NewCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "install",
Short: "install kmesh with all the resources",
Copy link
Member

Choose a reason for hiding this comment

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

Descriptive content use Kmesh, with the first letter capitalized.

@YaoZengzeng
Copy link
Member

The overall framework seems fine for me, @hzxuzhonghu PTAL.

func getYAMLFile(version string) string {
var url string
if version != "main" {
url = fmt.Sprintf("https://api.github.com/repos/kmesh-net/kmesh/contents/deploy/yaml?ref=release-%s", version)
Copy link
Member

Choose a reason for hiding this comment

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

I donot think this is quite correct, because?:

  1. we didn't update the image tag
  2. should not use the github branch, but use the tag instead

So in short should we use helm chart https://github.com/kmesh-net/kmesh/releases/download/v0.5.0/kmesh-helm-v0.5.0.tgz

or the OCI chart image https://github.com/orgs/kmesh-net/packages/container/package/kmesh-helm

Copy link
Author

@thebigbone thebigbone Oct 28, 2024

Choose a reason for hiding this comment

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

It is using release tag? Using helm will introduce new dependency which is totally unnecessary.

Copy link
Member

Choose a reason for hiding this comment

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

See the released version above

@YaoZengzeng
Copy link
Member

ping @hzxuzhonghu

@hzxuzhonghu
Copy link
Member

please see above comment, when you set version-=0.5, then you will install kmesh with latest image https://github.com/kmesh-net/kmesh/blob/release-0.5/deploy/yaml/kmesh.yaml#L72

This is not expected, can you replace that image?

I would suggest we support v0.5.0 or 0.5.0 rather than 0.5, see our releases

@thebigbone
Copy link
Author

thebigbone commented Nov 6, 2024

please see above comment, when you set version-=0.5, then you will install kmesh with latest image https://github.com/kmesh-net/kmesh/blob/release-0.5/deploy/yaml/kmesh.yaml#L72

This is not expected, can you replace that image?

I would suggest we support v0.5.0 or 0.5.0 rather than 0.5, see our releases

Should I just replace the image and get the yaml files from main then?

@hzxuzhonghu
Copy link
Member

Should I just replace the image and get the yaml files from main than?

This probably not work, think of the case that a yaml is updated because of some new features. The old image may cannot work with the new daemonset yaml

thebigbone and others added 8 commits November 7, 2024 15:16
Signed-off-by: thebigbone <[email protected]>
Signed-off-by: thebigbone <[email protected]>
Signed-off-by: thebigbone <[email protected]>
Signed-off-by: thebigbone <[email protected]>
Signed-off-by: thebigbone <[email protected]>
Co-authored-by: Tiger Xu / Zhonghu Xu <[email protected]>
Signed-off-by: thebigbone <[email protected]>
Signed-off-by: thebigbone <[email protected]>
@thebigbone
Copy link
Author

Removed the branch and instead using tags now.

hzxuzhonghu
hzxuzhonghu previously approved these changes Nov 12, 2024
Copy link
Member

@hzxuzhonghu hzxuzhonghu left a comment

Choose a reason for hiding this comment

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

/lgtm

YOu can fix it later

if err != nil {
log.Fatal(err)
}
defer resp.Body.Close()
Copy link
Member

Choose a reason for hiding this comment

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

nit: not use defer in a for loop

@kmesh-bot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: hzxuzhonghu

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kmesh-bot
Copy link
Collaborator

New changes are detected. LGTM label has been removed.

@kmesh-bot
Copy link
Collaborator

Adding label do-not-merge/contains-merge-commits because PR contains merge commits, which are not allowed in this repository.
Use git rebase to reapply your commits on top of the target branch. Detailed instructions for doing so can be found here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@thebigbone
Copy link
Author

The kube package was changed so it's not able to find ApplyYamlContents

@hzxuzhonghu
Copy link
Member

@LiZhenCheng9527
Copy link
Contributor

@thebigbone This PR can be merged after you pass CI.

@thebigbone
Copy link
Author

thebigbone commented Jan 22, 2025

Can you implement this method? Or use helm client https://github.com/kurator-dev/kurator/blob/ac68f35c8799773aea22643e39ca032a20e65fb7/pkg/client/client.go#L66

Should I use the istio's implementation directly in kube/client.go?

@thebigbone
Copy link
Author

ping @LiZhenCheng9527

log.Fatal(err)
}
} else {
err = cli.ApplyYAMLContents("", combinedYAMLFile)
Copy link
Contributor

Choose a reason for hiding this comment

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

There is no ApplyYamlContents in kmesh's kube pkg.
After fixing this problem, this PR can be merged.

Copy link
Author

Choose a reason for hiding this comment

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

Yes, which is why I asked if I should use the istio's implementation or the previous doServerSideApply function which I used at the beginning.

Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps we can implement applyYamlContents in Kmesh. If that doesn't work, we can switch back to the doServerSideApply function.

@thebigbone
Copy link
Author

I have implemented the method @LiZhenCheng9527

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make it easy to install a specific version of Kmesh
5 participants