@@ -11,6 +11,7 @@ import (
1111 . "github.com/onsi/ginkgo/v2"
1212 . "github.com/onsi/gomega"
1313 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
14+ clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
1415 "sigs.k8s.io/controller-runtime/pkg/client"
1516
1617 infrav1 "sigs.k8s.io/cluster-api-provider-kubevirt/api/v1alpha1"
@@ -27,6 +28,9 @@ func dump(ctx context.Context, kubeconfig, artifactsSuffix string) {
2728 output , err := cmd .CombinedOutput ()
2829 Expect (err ).To (Succeed (), string (output ))
2930
31+ By (fmt .Sprintf ("dumping cluster-api artifacts to %s" , artifactsPath ))
32+ dumpCAPIResources (ctx , artifactsPath )
33+
3034 By (fmt .Sprintf ("dumping CAPK artifacts to %s" , artifactsPath ))
3135 dumpCAPKResources (ctx , artifactsPath )
3236}
@@ -80,6 +84,66 @@ func dumpCAPKResources(ctx context.Context, artifactsDir string) {
8084 ).To (Succeed ())
8185}
8286
87+ func dumpCAPIResources (ctx context.Context , artifactsDir string ) {
88+ GinkgoHelper ()
89+
90+ By ("dump Clusters" )
91+ clusterList := & clusterv1.ClusterList {}
92+ Expect (k8sclient .List (ctx , clusterList , & client.ListOptions {})).To (Succeed ())
93+ for i := range clusterList .Items {
94+ item := & clusterList .Items [i ]
95+ item .SetManagedFields (nil )
96+ }
97+
98+ Expect (
99+ dumpJsonFile (clusterList , filepath .Join (artifactsDir , "0_clusters.json" )),
100+ ).To (Succeed ())
101+
102+ By ("dump Machines" )
103+ machineList := & clusterv1.MachineList {}
104+ Expect (k8sclient .List (ctx , machineList , & client.ListOptions {})).To (Succeed ())
105+ for i := range machineList .Items {
106+ item := & machineList .Items [i ]
107+ item .SetManagedFields (nil )
108+ }
109+ Expect (
110+ dumpJsonFile (machineList , filepath .Join (artifactsDir , "0_machines.json" )),
111+ ).To (Succeed ())
112+
113+ By ("dump MachineDeployments" )
114+ machineDeploymentList := & clusterv1.MachineDeploymentList {}
115+ Expect (k8sclient .List (ctx , machineDeploymentList , & client.ListOptions {})).To (Succeed ())
116+ for i := range machineDeploymentList .Items {
117+ item := & machineDeploymentList .Items [i ]
118+ item .SetManagedFields (nil )
119+ }
120+ Expect (
121+ dumpJsonFile (machineDeploymentList , filepath .Join (artifactsDir , "0_machinedeployments.json" )),
122+ ).To (Succeed ())
123+
124+ By ("dump KubevirtMachineTemplates" )
125+ machineHealthCheckList := & clusterv1.MachineHealthCheckList {}
126+ Expect (k8sclient .List (ctx , machineHealthCheckList , & client.ListOptions {})).To (Succeed ())
127+ for i := range machineHealthCheckList .Items {
128+ item := & machineHealthCheckList .Items [i ]
129+ item .SetManagedFields (nil )
130+ }
131+ Expect (
132+ dumpJsonFile (machineHealthCheckList , filepath .Join (artifactsDir , "0_machinehealthchecks.json" )),
133+ ).To (Succeed ())
134+
135+ By ("dump MachineSets" )
136+ machineSetList := & clusterv1.MachineSetList {}
137+ Expect (k8sclient .List (ctx , machineSetList , & client.ListOptions {})).To (Succeed ())
138+ for i := range machineSetList .Items {
139+ item := & machineSetList .Items [i ]
140+ item .SetManagedFields (nil )
141+ }
142+ Expect (
143+ dumpJsonFile (machineSetList , filepath .Join (artifactsDir , "0_machinesets.json" )),
144+ ).To (Succeed ())
145+ }
146+
83147func dumpJsonFile (objList metav1.ListInterface , artifactsFilePath string ) error {
84148 file , err := os .OpenFile (artifactsFilePath , os .O_WRONLY | os .O_CREATE | os .O_TRUNC , 0644 )
85149 if err != nil {
0 commit comments