@@ -25,6 +25,9 @@ import (
25
25
"github.com/kubernetes-sigs/ingress2gateway/pkg/i2gw"
26
26
"github.com/samber/lo"
27
27
"github.com/spf13/cobra"
28
+ "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
29
+ "k8s.io/apimachinery/pkg/runtime"
30
+ "k8s.io/apimachinery/pkg/runtime/serializer/json"
28
31
"k8s.io/cli-runtime/pkg/genericclioptions"
29
32
"k8s.io/cli-runtime/pkg/printers"
30
33
"k8s.io/client-go/tools/clientcmd"
@@ -179,6 +182,17 @@ func (pr *PrintRunner) outputResult(gatewayResources []i2gw.GatewayResources) {
179
182
}
180
183
}
181
184
185
+ for _ , r := range gatewayResources {
186
+ resourceCount += len (r .GatewayExtensions )
187
+ for _ , gatewayExtension := range r .GatewayExtensions {
188
+ gatewayExtension := gatewayExtension
189
+ fmt .Println ("---" )
190
+ if err := PrintUnstructuredAsYaml (& gatewayExtension ); err != nil {
191
+ fmt .Printf ("# Error printing %s gatewayExtension: %v\n " , gatewayExtension .GetName (), err )
192
+ }
193
+ }
194
+ }
195
+
182
196
if resourceCount == 0 {
183
197
msg := "No resources found"
184
198
if pr .namespaceFilter != "" {
@@ -188,6 +202,34 @@ func (pr *PrintRunner) outputResult(gatewayResources []i2gw.GatewayResources) {
188
202
}
189
203
}
190
204
205
+ func CastToUnstructured (obj runtime.Object ) (* unstructured.Unstructured , error ) {
206
+ // Convert the Kubernetes object to unstructured.Unstructured
207
+ unstructuredObj , err := runtime .DefaultUnstructuredConverter .ToUnstructured (obj )
208
+ if err != nil {
209
+ return nil , err
210
+ }
211
+
212
+ return & unstructured.Unstructured {Object : unstructuredObj }, nil
213
+ }
214
+
215
+ func PrintUnstructuredAsYaml (obj * unstructured.Unstructured ) error {
216
+ // Create a YAML serializer
217
+ serializer := json .NewSerializerWithOptions (json .DefaultMetaFactory , nil , nil ,
218
+ json.SerializerOptions {
219
+ Yaml : true ,
220
+ Pretty : true , // Optional: for better readability
221
+ Strict : true ,
222
+ })
223
+
224
+ // Encode the unstructured object to YAML
225
+ err := serializer .Encode (obj , os .Stdout )
226
+ if err != nil {
227
+ return err
228
+ }
229
+
230
+ return nil
231
+ }
232
+
191
233
// initializeResourcePrinter assign a specific type of printers.ResourcePrinter
192
234
// based on the outputFormat of the printRunner struct.
193
235
func (pr * PrintRunner ) initializeResourcePrinter () error {
0 commit comments