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

Collect the petset yamls #786

Merged
merged 1 commit into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ lint: $(BUILD_DIRS)
--env GO111MODULE=on \
--env GOFLAGS="-mod=vendor" \
$(BUILD_IMAGE) \
golangci-lint run --enable $(ADDTL_LINTERS) --timeout=10m --skip-files="generated.*\.go$\" --skip-dirs-use-default
golangci-lint run --enable $(ADDTL_LINTERS) --timeout=10m --exclude-files="generated.*\.go$\" --exclude-dirs-use-default

$(BUILD_DIRS):
@mkdir -p $@
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ require (
kmodules.xyz/monitoring-agent-api v0.30.2
kubedb.dev/apimachinery v0.51.0
kubedb.dev/db-client-go v0.6.0
kubeops.dev/petset v0.0.7
sigs.k8s.io/controller-runtime v0.18.4
sigs.k8s.io/yaml v1.4.0
stash.appscode.dev/apimachinery v0.38.0
Expand Down Expand Up @@ -147,7 +148,6 @@ require (
kmodules.xyz/prober v0.29.0 // indirect
kmodules.xyz/resource-metadata v0.24.1 // indirect
kubeops.dev/csi-driver-cacerts v0.1.0 // indirect
kubeops.dev/petset v0.0.7 // indirect
kubeops.dev/sidekick v0.0.10 // indirect
kubestash.dev/apimachinery v0.15.0 // indirect
sigs.k8s.io/gateway-api v1.1.0 // indirect
Expand Down
38 changes: 38 additions & 0 deletions pkg/debug/elasticsearch.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@ import (
_ "k8s.io/client-go/plugin/pkg/client/auth"
"k8s.io/klog/v2"
cmdutil "k8s.io/kubectl/pkg/cmd/util"
ps "kubeops.dev/petset/client/clientset/versioned"
)

type elasticsearchOpts struct {
db *dbapi.Elasticsearch
dbClient *cs.Clientset
psClient *ps.Clientset
podClient *kubernetes.Clientset

operatorNamespace string
Expand Down Expand Up @@ -80,6 +82,11 @@ func ElasticsearchDebugCMD(f cmdutil.Factory) *cobra.Command {
log.Fatal(err)
}

err = opts.collectForAllDBPetSets()
if err != nil {
log.Fatal(err)
}

err = opts.collectForAllDBPods()
if err != nil {
log.Fatal(err)
Expand Down Expand Up @@ -107,6 +114,11 @@ func newElasticsearchOpts(f cmdutil.Factory, dbName, namespace, operatorNS strin
return nil, err
}

psClient, err := ps.NewForConfig(config)
if err != nil {
return nil, err
}

podClient, err := kubernetes.NewForConfig(config)
if err != nil {
return nil, err
Expand All @@ -131,6 +143,7 @@ func newElasticsearchOpts(f cmdutil.Factory, dbName, namespace, operatorNS strin
opts := &elasticsearchOpts{
db: db,
dbClient: dbClient,
psClient: psClient,
podClient: podClient,
operatorNamespace: operatorNS,
dir: dir,
Expand Down Expand Up @@ -161,6 +174,31 @@ func (opts *elasticsearchOpts) collectOperatorLogs() error {
return nil
}

func (opts *elasticsearchOpts) collectForAllDBPetSets() error {
psLabels := labels.SelectorFromSet(opts.db.OffshootLabels()).String()
petsets, err := opts.psClient.AppsV1().PetSets(opts.db.Namespace).List(context.TODO(), metav1.ListOptions{
LabelSelector: psLabels,
})
if err != nil {
return err
}

psYamlDir := path.Join(opts.dir, yamlsDir, "petsets")
err = os.MkdirAll(psYamlDir, dirPerm)
if err != nil {
return err
}

for _, p := range petsets.Items {
err = writeYaml(&p, psYamlDir)
if err != nil {
return err
}

}
return nil
}

func (opts *elasticsearchOpts) collectForAllDBPods() error {
dbLabels := labels.SelectorFromSet(opts.db.OffshootLabels()).String()
pods, err := opts.podClient.CoreV1().Pods(opts.db.Namespace).List(context.TODO(), metav1.ListOptions{
Expand Down
38 changes: 38 additions & 0 deletions pkg/debug/mariadb.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@ import (
_ "k8s.io/client-go/plugin/pkg/client/auth"
"k8s.io/klog/v2"
cmdutil "k8s.io/kubectl/pkg/cmd/util"
ps "kubeops.dev/petset/client/clientset/versioned"
)

type mariadbOpts struct {
db *dbapi.MariaDB
dbClient *cs.Clientset
psClient *ps.Clientset
podClient *kubernetes.Clientset

operatorNamespace string
Expand Down Expand Up @@ -80,6 +82,11 @@ func MariaDBDebugCMD(f cmdutil.Factory) *cobra.Command {
log.Fatal(err)
}

err = opts.collectForAllDBPetSets()
if err != nil {
log.Fatal(err)
}

err = opts.collectForAllDBPods()
if err != nil {
log.Fatal(err)
Expand Down Expand Up @@ -107,6 +114,11 @@ func newMariadbOpts(f cmdutil.Factory, dbName, namespace, operatorNS string) (*m
return nil, err
}

psClient, err := ps.NewForConfig(config)
if err != nil {
return nil, err
}

podClient, err := kubernetes.NewForConfig(config)
if err != nil {
return nil, err
Expand All @@ -131,6 +143,7 @@ func newMariadbOpts(f cmdutil.Factory, dbName, namespace, operatorNS string) (*m
opts := &mariadbOpts{
db: db,
dbClient: dbClient,
psClient: psClient,
podClient: podClient,
operatorNamespace: operatorNS,
dir: dir,
Expand Down Expand Up @@ -161,6 +174,31 @@ func (opts *mariadbOpts) collectOperatorLogs() error {
return nil
}

func (opts *mariadbOpts) collectForAllDBPetSets() error {
psLabels := labels.SelectorFromSet(opts.db.OffshootLabels()).String()
petsets, err := opts.psClient.AppsV1().PetSets(opts.db.Namespace).List(context.TODO(), metav1.ListOptions{
LabelSelector: psLabels,
})
if err != nil {
return err
}

psYamlDir := path.Join(opts.dir, yamlsDir, "petsets")
err = os.MkdirAll(psYamlDir, dirPerm)
if err != nil {
return err
}

for _, p := range petsets.Items {
err = writeYaml(&p, psYamlDir)
if err != nil {
return err
}

}
return nil
}

func (opts *mariadbOpts) collectForAllDBPods() error {
dbLabels := labels.SelectorFromSet(opts.db.OffshootLabels()).String()
pods, err := opts.podClient.CoreV1().Pods(opts.db.Namespace).List(context.TODO(), metav1.ListOptions{
Expand Down
38 changes: 38 additions & 0 deletions pkg/debug/mongodb.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@ import (
_ "k8s.io/client-go/plugin/pkg/client/auth"
"k8s.io/klog/v2"
cmdutil "k8s.io/kubectl/pkg/cmd/util"
ps "kubeops.dev/petset/client/clientset/versioned"
)

type mongodbOpts struct {
db *dbapi.MongoDB
dbClient *cs.Clientset
psClient *ps.Clientset
podClient *kubernetes.Clientset

operatorNamespace string
Expand Down Expand Up @@ -80,6 +82,11 @@ func MongoDBDebugCMD(f cmdutil.Factory) *cobra.Command {
log.Fatal(err)
}

err = opts.collectForAllDBPetSets()
if err != nil {
log.Fatal(err)
}

err = opts.collectForAllDBPods()
if err != nil {
log.Fatal(err)
Expand Down Expand Up @@ -107,6 +114,11 @@ func newMongodbOpts(f cmdutil.Factory, dbName, namespace, operatorNS string) (*m
return nil, err
}

psClient, err := ps.NewForConfig(config)
if err != nil {
return nil, err
}

podClient, err := kubernetes.NewForConfig(config)
if err != nil {
return nil, err
Expand All @@ -131,6 +143,7 @@ func newMongodbOpts(f cmdutil.Factory, dbName, namespace, operatorNS string) (*m
opts := &mongodbOpts{
db: db,
dbClient: dbClient,
psClient: psClient,
podClient: podClient,
operatorNamespace: operatorNS,
dir: dir,
Expand Down Expand Up @@ -161,6 +174,31 @@ func (opts *mongodbOpts) collectOperatorLogs() error {
return nil
}

func (opts *mongodbOpts) collectForAllDBPetSets() error {
psLabels := labels.SelectorFromSet(opts.db.OffshootLabels()).String()
petsets, err := opts.psClient.AppsV1().PetSets(opts.db.Namespace).List(context.TODO(), metav1.ListOptions{
LabelSelector: psLabels,
})
if err != nil {
return err
}

psYamlDir := path.Join(opts.dir, yamlsDir, "petsets")
err = os.MkdirAll(psYamlDir, dirPerm)
if err != nil {
return err
}

for _, p := range petsets.Items {
err = writeYaml(&p, psYamlDir)
if err != nil {
return err
}

}
return nil
}

func (opts *mongodbOpts) collectForAllDBPods() error {
dbLabels := labels.SelectorFromSet(opts.db.OffshootLabels()).String()
pods, err := opts.podClient.CoreV1().Pods(opts.db.Namespace).List(context.TODO(), metav1.ListOptions{
Expand Down
38 changes: 38 additions & 0 deletions pkg/debug/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@ import (
_ "k8s.io/client-go/plugin/pkg/client/auth"
"k8s.io/klog/v2"
cmdutil "k8s.io/kubectl/pkg/cmd/util"
ps "kubeops.dev/petset/client/clientset/versioned"
)

type mysqlOpts struct {
db *dbapi.MySQL
dbClient *cs.Clientset
psClient *ps.Clientset
podClient *kubernetes.Clientset

operatorNamespace string
Expand Down Expand Up @@ -80,6 +82,11 @@ func MySQLDebugCMD(f cmdutil.Factory) *cobra.Command {
log.Fatal(err)
}

err = opts.collectForAllDBPetSets()
if err != nil {
log.Fatal(err)
}

err = opts.collectForAllDBPods()
if err != nil {
log.Fatal(err)
Expand Down Expand Up @@ -107,6 +114,11 @@ func newMysqlOpts(f cmdutil.Factory, dbName, namespace, operatorNS string) (*mys
return nil, err
}

psClient, err := ps.NewForConfig(config)
if err != nil {
return nil, err
}

podClient, err := kubernetes.NewForConfig(config)
if err != nil {
return nil, err
Expand All @@ -131,6 +143,7 @@ func newMysqlOpts(f cmdutil.Factory, dbName, namespace, operatorNS string) (*mys
opts := &mysqlOpts{
db: db,
dbClient: dbClient,
psClient: psClient,
podClient: podClient,
operatorNamespace: operatorNS,
dir: dir,
Expand Down Expand Up @@ -161,6 +174,31 @@ func (opts *mysqlOpts) collectOperatorLogs() error {
return nil
}

func (opts *mysqlOpts) collectForAllDBPetSets() error {
psLabels := labels.SelectorFromSet(opts.db.OffshootLabels()).String()
petsets, err := opts.psClient.AppsV1().PetSets(opts.db.Namespace).List(context.TODO(), metav1.ListOptions{
LabelSelector: psLabels,
})
if err != nil {
return err
}

psYamlDir := path.Join(opts.dir, yamlsDir, "petsets")
err = os.MkdirAll(psYamlDir, dirPerm)
if err != nil {
return err
}

for _, p := range petsets.Items {
err = writeYaml(&p, psYamlDir)
if err != nil {
return err
}

}
return nil
}

func (opts *mysqlOpts) collectForAllDBPods() error {
dbLabels := labels.SelectorFromSet(opts.db.OffshootLabels()).String()
pods, err := opts.podClient.CoreV1().Pods(opts.db.Namespace).List(context.TODO(), metav1.ListOptions{
Expand Down
Loading
Loading