@@ -5,8 +5,15 @@ import (
55 "fmt"
66 "os"
77
8+ "github.com/openmcp-project/controller-utils/pkg/clusters"
89 "github.com/openmcp-project/controller-utils/pkg/logging"
10+ clustersv1alpha1 "github.com/openmcp-project/openmcp-operator/api/clusters/v1alpha1"
911 "github.com/spf13/cobra"
12+ apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
13+ "k8s.io/apimachinery/pkg/runtime"
14+ utilruntime "k8s.io/apimachinery/pkg/util/runtime"
15+ clientgoscheme "k8s.io/client-go/kubernetes/scheme"
16+ "k8s.io/client-go/tools/clientcmd/api"
1017
1118 ctrl "sigs.k8s.io/controller-runtime"
1219 "sigs.k8s.io/yaml"
@@ -21,7 +28,9 @@ func NewUsageOperatorCommand(ctx context.Context) *cobra.Command {
2128 cmd .SetErr (os .Stderr )
2229
2330 so := & SharedOptions {
24- RawSharedOptions : & RawSharedOptions {},
31+ RawSharedOptions : & RawSharedOptions {
32+ PlatformCluster : clusters .New ("platform" ),
33+ },
2534 }
2635
2736 so .AddPersistentFlags (cmd )
@@ -35,6 +44,8 @@ func NewUsageOperatorCommand(ctx context.Context) *cobra.Command {
3544type RawSharedOptions struct {
3645 Environment string `json:"environment"`
3746 DryRun bool `json:"dry-run"`
47+
48+ PlatformCluster * clusters.Cluster `json:"platform-cluster"`
3849}
3950
4051type SharedOptions struct {
@@ -50,9 +61,25 @@ func (o *SharedOptions) AddPersistentFlags(cmd *cobra.Command) {
5061 // misc
5162 cmd .PersistentFlags ().BoolVar (& o .DryRun , "dry-run" , false , "If set, the command aborts after evaluation of the given flags." )
5263 cmd .PersistentFlags ().StringVar (& o .Environment , "environment" , "" , "Environment name. Required. This is used to distinguish between different environments that are watching the same Onboarding cluster. Must be globally unique." )
64+
65+ o .PlatformCluster .RegisterSingleConfigPathFlag (cmd .PersistentFlags ())
5366}
5467
5568func (o * SharedOptions ) Complete () error {
69+ // platform cluster
70+ if err := o .PlatformCluster .InitializeRESTConfig (); err != nil {
71+ return fmt .Errorf ("unable to initialize platform cluster rest config: %w" , err )
72+ }
73+ platformScheme := runtime .NewScheme ()
74+ utilruntime .Must (clientgoscheme .AddToScheme (platformScheme ))
75+ utilruntime .Must (apiextensionsv1 .AddToScheme (platformScheme ))
76+ utilruntime .Must (clustersv1alpha1 .AddToScheme (platformScheme ))
77+ utilruntime .Must (api .AddToScheme (platformScheme ))
78+
79+ if err := o .PlatformCluster .InitializeClient (platformScheme ); err != nil {
80+ return fmt .Errorf ("unable to initialize platform cluster client: %w" , err )
81+ }
82+
5683 // build logger
5784 log , err := logging .GetLogger ()
5885 if err != nil {
@@ -74,7 +101,9 @@ func (o *SharedOptions) PrintRaw(cmd *cobra.Command) {
74101}
75102
76103func (o * SharedOptions ) PrintCompleted (cmd * cobra.Command ) {
77- raw := map [string ]any {}
104+ raw := map [string ]any {
105+ "platform-cluster" : o .PlatformCluster .APIServerEndpoint (),
106+ }
78107 data , err := yaml .Marshal (raw )
79108 if err != nil {
80109 cmd .Println (fmt .Errorf ("error marshalling completed shared options: %w" , err ).Error ())
0 commit comments