Skip to content

Commit

Permalink
chore: update debug.mk with utilities, especially delve
Browse files Browse the repository at this point in the history
  • Loading branch information
powerfooI committed Nov 9, 2023
1 parent 57a343b commit e523d2b
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 42 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,5 @@ deploy/*secret*

# Kubernetes Generated files - skip generated files, except for vendored files
# !vendor/**/zz_generated.*

.vscode
32 changes: 17 additions & 15 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,21 +178,23 @@ func main() {
setupLog.Error(err, "unable to create controller", "controller", "OBTenantOperation")
os.Exit(1)
}
if err = (&v1alpha1.OBTenantBackupPolicy{}).SetupWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "OBTenantBackupPolicy")
os.Exit(1)
}
if err = (&v1alpha1.OBTenant{}).SetupWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "OBTenant")
os.Exit(1)
}
if err = (&v1alpha1.OBTenantOperation{}).SetupWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "OBTenantOperation")
os.Exit(1)
}
if err = (&v1alpha1.OBCluster{}).SetupWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "OBCluster")
os.Exit(1)
if os.Getenv("DISABLE_WEBHOOKS") != "true" {
if err = (&v1alpha1.OBTenantBackupPolicy{}).SetupWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "OBTenantBackupPolicy")
os.Exit(1)
}
if err = (&v1alpha1.OBTenant{}).SetupWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "OBTenant")
os.Exit(1)
}
if err = (&v1alpha1.OBTenantOperation{}).SetupWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "OBTenantOperation")
os.Exit(1)
}
if err = (&v1alpha1.OBCluster{}).SetupWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "OBCluster")
os.Exit(1)
}
}
//+kubebuilder:scaffold:builder

Expand Down
54 changes: 27 additions & 27 deletions make/debug.mk
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
# All targets here are phony
##@ Debug

.PHONY: connect gettenants getpolicy getbackupjobs getcluster getobserver getrestorejobs getpods
.PHONY: connect root-pwd run-delve install-delve

connect:
$(eval nodeHost = $(shell kubectl get pods -o jsonpath='{.items[1].status.podIP}'))
NS ?= default

connect: root-pwd
$(eval nodeHost = $(shell kubectl -n ${NS} get pods -l ref-obcluster -o jsonpath='{.items[0].status.podIP}'))
ifdef TENANT
$(eval secretName = $(shell kubectl get obtenant ${TENANT} -o jsonpath='{.status.credentials.root}'))
$(eval tenantName = $(shell kubectl get obtenant ${TENANT} -o jsonpath='{.spec.tenantName}'))
$(if $(strip $(secretName)), $(eval pwd = $(shell kubectl get secret $(secretName) -o jsonpath='{.data.password}' | base64 -d)), )
$(eval secretName = $(shell kubectl -n ${NS} get obtenant ${TENANT} -o jsonpath='{.status.credentials.root}'))
$(eval tenantName = $(shell kubectl -n ${NS} get obtenant ${TENANT} -o jsonpath='{.spec.tenantName}'))
$(if $(strip $(secretName)), $(eval pwd = $(shell kubectl -n ${NS} get secret $(secretName) -o jsonpath='{.data.password}' | base64 -d)), )
$(if $(strip $(pwd)), mysql -h$(nodeHost) -P2881 -A -uroot@$(tenantName) -p$(pwd) -Doceanbase, mysql -h$(nodeHost) -P2881 -A -uroot@$(tenantName) -Doceanbase)
else
mysql -h$(nodeHost) -P2881 -A -uroot -p -Doceanbase
mysql -h$(nodeHost) -P2881 -A -uroot -p -Doceanbase -p$(pwd)
endif

gettenants: ## Get all tenants
@kubectl get -n oceanbase obtenant -o wide

getpolicy: ## Get all backup policy
@kubectl get -n oceanbase obtenantbackuppolicy

getbackupjobs: ## Get all backup jobs
@kubectl get -n oceanbase obtenantbackup

getcluster: ## Get all obclusters
@kubectl get -n oceanbase obcluster

getobserver: ## Get all observers
@kubectl get -n oceanbase observer

getrestorejobs:
@kubectl get -n oceanbase obtenantrestore

getpods:
@kubectl get -n oceanbase pods -o wide
root-pwd:
ifdef CLUSTER
$(eval clusterName = ${CLUSTER})
else
$(eval clusterName = $(shell kubectl -n ${NS} get obcluster -o jsonpath='{.items[0].metadata.name}'))
endif
$(eval secretName = $(shell kubectl -n ${NS} get obcluster $(clusterName) -o jsonpath='{.spec.userSecrets.root}'))
$(eval nodeHost = $(shell kubectl -n ${NS} get pods -l ref-obcluster=$(clusterName) -o jsonpath='{.items[0].status.podIP}'))
$(if $(strip $(secretName)), $(eval pwd = $(shell kubectl -n ${NS} get secret $(secretName) -o jsonpath='{.data.password}' | base64 -d)), )
@echo root pwd of sys of cluster '$(clusterName)' is $(pwd)

## Delve is a debugger for the Go programming language. More info: https://github.com/go-delve/delve
run-delve: generate fmt vet manifests ## Run with Delve for development purposes against the configured Kubernetes cluster in ~/.kube/config
go build -gcflags "all=-trimpath=$(shell go env GOPATH)" -o bin/manager cmd/main.go
DISABLE_WEBHOOKS=true dlv --listen=:2345 --headless=true --api-version=2 --accept-multiclient exec ./bin/manager

install-delve: ## Install delve, a debugger for the Go programming language. More info: https://github.com/go-delve/delve
go install github.com/go-delve/delve/cmd/dlv@master

0 comments on commit e523d2b

Please sign in to comment.