-
Notifications
You must be signed in to change notification settings - Fork 28
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
core: move project to golang #79
Conversation
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.
A few questions to get started
90401ac
to
aa7a5fd
Compare
btw this how ci is executing commands, not sure why
|
e5407b8
to
52e573f
Compare
cmd/ceph/ceph.go
Outdated
@@ -0,0 +1,35 @@ | |||
/* |
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.
How about if we put all the go files with the cobra definitions directly in cmd/
? Seems like we don't need the subdirectories for ceph
, rbd
, etc.
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 kept main.go under cmd folder and all other commands inside commands
folder otherwise everything go file will be under main package and now current structure seems okay to me
cmd/ceph/ceph.go
Outdated
var CephCmd = &cobra.Command{ | ||
Use: "ceph", | ||
Short: "call a 'ceph' CLI command with arbitrary args", | ||
Long: `call a 'ceph' CLI command with arbitrary args`, |
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 we don't define Long, will it default to the same as Short? It would be nice to avoid the redundancy, or else define a different Short and Long description.
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.
removed the Long
6d0346c
to
1da0c4e
Compare
c1f4493
to
aee859e
Compare
.github/workflows/go-test.yaml
Outdated
|
||
- name: build the binary | ||
run: | | ||
go build -o kubectl-rook-ceph cmd/main.go |
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 running go build in this action, we need a makefile. Then developers can easily and consistently build locally during development, and the CI can also call make
. But let's try to make it much simpler than the rook makefile. :)
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.
created makefile, I think this is one of the simplest makefile you will come across 😅
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.
Simple makefiles are the best kind!
aee859e
to
03cc1b1
Compare
03cc1b1
to
83bd39f
Compare
pkg/mons/mon-endpoints.go
Outdated
|
||
const monConfigMap = "rook-ceph-mon-endpoints" | ||
|
||
func GetMonEndpoint(clusterNamespace 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.
Let's add a unit test for this method so we can establish the unit tests from the start. You'll just need to have the kube client as a parameter to the method.
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 method is not returning anything, how we should write the unit test?
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.
As discussed, how about refactoring lines 40-44 to a separate method that can be unit tested.
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.
added a unit-test
4fe837b
to
b6207fe
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.
Some nits. LGTM
b6207fe
to
06cec60
Compare
|
||
RootCmd.PersistentFlags().StringVar(&KubeConfig, "kubeconfig", "", "kubernetes config path") | ||
RootCmd.PersistentFlags().StringVar(&OperatorNamespace, "opeator-namespace", "rook-ceph", "Kubernetes namespace where rook operator is running") | ||
RootCmd.PersistentFlags().StringVar(&CephClusterNamespace, "namespace", "rook-ceph", "Kubernetes namespace where ceph cluster is created") |
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.
How the krew cmd will run can you give a doc example for ceph health,
I can't how you might be calling the status, does it like calling the k8s client and then calling ceph cmd through it?
And one more question/doubt What if we just create and call the cmds from toolbox and wrap them into a go package?
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.
Currently, we are using operator pod for running ceph commands and toolbox and operator pod are almost same. So we prefer rook operator pod as rook/rook also uses operator pod for running ceph command internally
pkg/k8sutil/exec.go
Outdated
clientcmd.NewDefaultClientConfigLoadingRules(), | ||
&clientcmd.ConfigOverrides{}, | ||
) | ||
rest, err := kubeconfig.ClientConfig() |
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.
Seems like these lines 42-49 are duplicated from what is in GetKubeClient(). Instead of duplicating, how about a different helper method instead of GetKubeClient() that gives back the rest
and client
? Or some other refactoring.
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.
In the future we may also want to unit test commands where we can mock K8s and the exec commands, like we do in the Rook core. So I'd suggest that this method should take the kubeconfig as a parameter, then the core implementation takes parameters for the context that can be mocked. The kubeconfig would likely be initialized at the top layer under the cmd package.
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.
now, I'm returning the rest and client from GetKubeClient
only.
I'm not sure about second part could you refer some example
pkg/mons/mon-endpoints.go
Outdated
|
||
const monConfigMap = "rook-ceph-mon-endpoints" | ||
|
||
func GetMonEndpoint(clusterNamespace 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.
As discussed, how about refactoring lines 40-44 to a separate method that can be unit tested.
06cec60
to
1a349cb
Compare
Rook has a method to create the context, which initializes most of the context here. By default, it will create types that will exec real commands and expect a real k8s cluster. But then the unit tests can mock the exec and k8s methods by passing a different context, for example as created here for the K8s tests, or search for |
1a349cb
to
4bf91e2
Compare
I think I'm not very much confident about how that's works, may be discussed in call will make it clear. |
4bf91e2
to
202f903
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.
Approved with one more suggestion, thanks
Makefile
Outdated
build: | ||
gofmt -w $(shell find . -type f -name '*.go') | ||
@echo | ||
env GOOS=$(shell go env GOOS) GOARCH=$(shell go env GOARCH) go build -o kubectl-rook-ceph cmd/main.go |
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.
After a build, the binary shows up in the local repo as a new file, and could be accidentally committed. How about if we output the binary to a bin/
subfolder, then add bin
to a .gitignore
?
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 PTAL
starting migration from bash to go, starting with basic ceph commands and getting mons endpoint Signed-off-by: subhamkrai <srai@redhat.com>
202f903
to
4af4d5b
Compare
LGTM! |
starting migration from bash to go, starting with
basic ceph commands and getting mons endpoint
Signed-off-by: subhamkrai srai@redhat.com