@@ -34,11 +34,13 @@ import (
3434 _ "k8s.io/client-go/plugin/pkg/client/auth"
3535 "k8s.io/klog/v2"
3636 cmdutil "k8s.io/kubectl/pkg/cmd/util"
37+ ps "kubeops.dev/petset/client/clientset/versioned"
3738)
3839
3940type elasticsearchOpts struct {
4041 db * dbapi.Elasticsearch
4142 dbClient * cs.Clientset
43+ psClient * ps.Clientset
4244 podClient * kubernetes.Clientset
4345
4446 operatorNamespace string
@@ -80,6 +82,11 @@ func ElasticsearchDebugCMD(f cmdutil.Factory) *cobra.Command {
8082 log .Fatal (err )
8183 }
8284
85+ err = opts .collectForAllDBPetSets ()
86+ if err != nil {
87+ log .Fatal (err )
88+ }
89+
8390 err = opts .collectForAllDBPods ()
8491 if err != nil {
8592 log .Fatal (err )
@@ -107,6 +114,11 @@ func newElasticsearchOpts(f cmdutil.Factory, dbName, namespace, operatorNS strin
107114 return nil , err
108115 }
109116
117+ psClient , err := ps .NewForConfig (config )
118+ if err != nil {
119+ return nil , err
120+ }
121+
110122 podClient , err := kubernetes .NewForConfig (config )
111123 if err != nil {
112124 return nil , err
@@ -131,6 +143,7 @@ func newElasticsearchOpts(f cmdutil.Factory, dbName, namespace, operatorNS strin
131143 opts := & elasticsearchOpts {
132144 db : db ,
133145 dbClient : dbClient ,
146+ psClient : psClient ,
134147 podClient : podClient ,
135148 operatorNamespace : operatorNS ,
136149 dir : dir ,
@@ -161,6 +174,31 @@ func (opts *elasticsearchOpts) collectOperatorLogs() error {
161174 return nil
162175}
163176
177+ func (opts * elasticsearchOpts ) collectForAllDBPetSets () error {
178+ psLabels := labels .SelectorFromSet (opts .db .OffshootLabels ()).String ()
179+ petsets , err := opts .psClient .AppsV1 ().PetSets (opts .db .Namespace ).List (context .TODO (), metav1.ListOptions {
180+ LabelSelector : psLabels ,
181+ })
182+ if err != nil {
183+ return err
184+ }
185+
186+ psYamlDir := path .Join (opts .dir , yamlsDir , "petsets" )
187+ err = os .MkdirAll (psYamlDir , dirPerm )
188+ if err != nil {
189+ return err
190+ }
191+
192+ for _ , p := range petsets .Items {
193+ err = writeYaml (& p , psYamlDir )
194+ if err != nil {
195+ return err
196+ }
197+
198+ }
199+ return nil
200+ }
201+
164202func (opts * elasticsearchOpts ) collectForAllDBPods () error {
165203 dbLabels := labels .SelectorFromSet (opts .db .OffshootLabels ()).String ()
166204 pods , err := opts .podClient .CoreV1 ().Pods (opts .db .Namespace ).List (context .TODO (), metav1.ListOptions {
0 commit comments