Skip to content

Commit 1ed9400

Browse files
committed
Unify ClusterProfiles provider implementation into cluster-inventory-api provider
Signed-off-by: Shingo Omura <[email protected]>
1 parent c5701e0 commit 1ed9400

File tree

16 files changed

+459
-1581
lines changed

16 files changed

+459
-1581
lines changed

examples/cluster-inventory-api/go.sum

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,10 @@ github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9G
6969
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
7070
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
7171
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
72+
github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
73+
github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU=
7274
github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
75+
github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU=
7376
github.com/onsi/ginkgo/v2 v2.22.0 h1:Yed107/8DjTr0lKCNt7Dn8yQ6ybuDRQoMGrNFKzMfHg=
7477
github.com/onsi/ginkgo/v2 v2.22.0/go.mod h1:7Du3c42kxCUegi0IImZ1wUQzMBVecgIHjR1C+NkhLQo=
7578
github.com/onsi/gomega v1.36.1 h1:bJDPBO7ibjxcbHMgSCoo4Yj18UWbKDlLwX1x9sybDcw=
@@ -158,6 +161,8 @@ gopkg.in/evanphx/json-patch.v4 v4.12.0 h1:n6jtcsulIzXPJaxegRbvFNNrZDjbij7ny3gmSP
158161
gopkg.in/evanphx/json-patch.v4 v4.12.0/go.mod h1:p8EYWUEYMpynmqDbY58zCKCFZw8pRWMG4EsWvDvM72M=
159162
gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc=
160163
gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw=
164+
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
165+
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
161166
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
162167
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
163168
k8s.io/api v0.33.1 h1:tA6Cf3bHnLIrUK4IqEgb2v++/GYUtqiu9sRVk3iBXyw=

examples/cluster-inventory-api/main.go

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@ package main
1919
import (
2020
"context"
2121
"errors"
22+
"flag"
2223
"os"
2324

2425
"golang.org/x/sync/errgroup"
2526
clusterinventoryv1alpha1 "sigs.k8s.io/cluster-inventory-api/apis/v1alpha1"
27+
"sigs.k8s.io/cluster-inventory-api/pkg/credentials"
2628

2729
corev1 "k8s.io/api/core/v1"
2830
apierrors "k8s.io/apimachinery/pkg/api/errors"
@@ -50,6 +52,9 @@ func init() {
5052
}
5153

5254
func main() {
55+
credentialsProviderFile := credentials.SetupProviderFileFlag()
56+
flag.Parse()
57+
5358
ctrllog.SetLogger(zap.New(zap.UseDevMode(true)))
5459
entryLog := ctrllog.Log.WithName("entrypoint")
5560
ctx := signals.SetupSignalHandler()
@@ -61,13 +66,25 @@ func main() {
6166
os.Exit(1)
6267
}
6368

64-
// Create the provider against the local manager.
69+
// Load credential providers from configuration file
70+
credentialsProvider, err := credentials.NewFromFile(*credentialsProviderFile)
71+
if err != nil {
72+
entryLog.Error(err, "Got error reading credentials providers")
73+
os.Exit(1)
74+
}
75+
76+
// Create the provider.
6577
provider, err := clusterinventoryapi.New(clusterinventoryapi.Options{
78+
// Specifying the strategy how to fetch kubeconfig from ClusterProfile.
6679
KubeconfigStrategyOption: kubeconfigstrategy.Option{
67-
// Use the Secret strategy with a specific consumer name.
68-
Secret: kubeconfigstrategy.SecretStrategyOption{
69-
ConsumerName: "cluster-inventory-api-consumer",
80+
CredentialsProvider: &kubeconfigstrategy.CredentialsProviderOption{
81+
Provider: credentialsProvider,
7082
},
83+
// // Alternative:
84+
// // You can use the Secret strategy, but it is not recommended for production use.
85+
// Secret: &kubeconfigstrategy.SecretStrategyOption{
86+
// ConsumerName: "cluster-inventory-api-consumer",
87+
// },
7188
},
7289
})
7390
if err != nil {
@@ -76,7 +93,7 @@ func main() {
7693
}
7794

7895
// Create a multi-cluster manager attached to the provider.
79-
entryLog.Info("Setting up local manager")
96+
entryLog.Info("Setting up manager")
8097
mcMgr, err := mcmanager.New(cfg, provider, manager.Options{
8198
LeaderElection: false,
8299
Metrics: metricsserver.Options{

examples/clusterprofile/go.mod

Lines changed: 0 additions & 73 deletions
This file was deleted.

0 commit comments

Comments
 (0)