-
Notifications
You must be signed in to change notification settings - Fork 21
π± Cluster Inventory(ClusterProfile
) API Provider
#48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
everpeace
wants to merge
10
commits into
kubernetes-sigs:main
Choose a base branch
from
everpeace:cluster-inventory-api
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
eb89258
Added Cluster Inventory API provider
everpeace 11aa126
Added an example for the Cluster Inventory API provider
everpeace b4dc008
Update examples/cluster-inventory-api/main.go
everpeace cefe93a
Support re-engaging a cluster in multicluster manager when the kubecoβ¦
everpeace 28ad979
Added test for cluster inventory API provider
everpeace b35387b
Introduce KubeconfigStrategy in cluster-inventory-api provider
everpeace 058033f
delete unnecessary comments in test
everpeace b23922a
multicluster-runtime should be "replace" in go.mod
everpeace 3ff3014
Use GetLocalManager() in multi-cluster manager instead of creating a β¦
everpeace 144110c
fix typo
everpeace File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
module sigs.k8s.io/multicluster-runtime/examples/cluster-inventory-api | ||
|
||
go 1.24.2 | ||
|
||
replace ( | ||
sigs.k8s.io/multicluster-runtime => ../.. | ||
sigs.k8s.io/multicluster-runtime/providers/cluster-inventory-api => ../../providers/cluster-inventory-api | ||
) | ||
|
||
require ( | ||
golang.org/x/sync v0.15.0 | ||
k8s.io/api v0.33.1 | ||
k8s.io/apimachinery v0.33.1 | ||
k8s.io/client-go v0.33.1 | ||
sigs.k8s.io/cluster-inventory-api v0.0.0-20250318031555-c7c0594aa53b | ||
sigs.k8s.io/controller-runtime v0.21.0 | ||
sigs.k8s.io/multicluster-runtime v0.21.0-alpha.8 | ||
sigs.k8s.io/multicluster-runtime/providers/cluster-inventory-api v0.0.0-00010101000000-000000000000 | ||
) | ||
|
||
require ( | ||
github.com/beorn7/perks v1.0.1 // indirect | ||
github.com/cespare/xxhash/v2 v2.3.0 // indirect | ||
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect | ||
github.com/emicklei/go-restful/v3 v3.12.2 // indirect | ||
github.com/evanphx/json-patch/v5 v5.9.11 // indirect | ||
github.com/fsnotify/fsnotify v1.7.0 // indirect | ||
github.com/fxamacker/cbor/v2 v2.7.0 // indirect | ||
github.com/go-logr/logr v1.4.2 // indirect | ||
github.com/go-logr/zapr v1.3.0 // indirect | ||
github.com/go-openapi/jsonpointer v0.21.1 // indirect | ||
github.com/go-openapi/jsonreference v0.21.0 // indirect | ||
github.com/go-openapi/swag v0.23.1 // indirect | ||
github.com/gogo/protobuf v1.3.2 // indirect | ||
github.com/google/btree v1.1.3 // indirect | ||
github.com/google/gnostic-models v0.6.9 // indirect | ||
github.com/google/go-cmp v0.7.0 // indirect | ||
github.com/google/uuid v1.6.0 // indirect | ||
github.com/josharian/intern v1.0.0 // indirect | ||
github.com/json-iterator/go v1.1.12 // indirect | ||
github.com/mailru/easyjson v0.9.0 // indirect | ||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect | ||
github.com/modern-go/reflect2 v1.0.2 // indirect | ||
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect | ||
github.com/pkg/errors v0.9.1 // indirect | ||
github.com/prometheus/client_golang v1.22.0 // indirect | ||
github.com/prometheus/client_model v0.6.1 // indirect | ||
github.com/prometheus/common v0.62.0 // indirect | ||
github.com/prometheus/procfs v0.15.1 // indirect | ||
github.com/spf13/pflag v1.0.5 // indirect | ||
github.com/x448/float16 v0.8.4 // indirect | ||
go.uber.org/multierr v1.11.0 // indirect | ||
go.uber.org/zap v1.27.0 // indirect | ||
golang.org/x/net v0.38.0 // indirect | ||
golang.org/x/oauth2 v0.28.0 // indirect | ||
golang.org/x/sys v0.31.0 // indirect | ||
golang.org/x/term v0.30.0 // indirect | ||
golang.org/x/text v0.23.0 // indirect | ||
golang.org/x/time v0.11.0 // indirect | ||
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect | ||
google.golang.org/protobuf v1.36.5 // indirect | ||
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect | ||
gopkg.in/inf.v0 v0.9.1 // indirect | ||
gopkg.in/yaml.v3 v3.0.1 // indirect | ||
k8s.io/apiextensions-apiserver v0.33.0 // indirect | ||
k8s.io/klog/v2 v2.130.1 // indirect | ||
k8s.io/kube-openapi v0.0.0-20250318190949-c8a335a9a2ff // indirect | ||
k8s.io/utils v0.0.0-20241210054802-24370beab758 // indirect | ||
sigs.k8s.io/json v0.0.0-20241014173422-cfa47c3a1cc8 // indirect | ||
sigs.k8s.io/randfill v1.0.0 // indirect | ||
sigs.k8s.io/structured-merge-diff/v4 v4.6.0 // indirect | ||
sigs.k8s.io/yaml v1.4.0 // indirect | ||
) |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
/* | ||
Copyright 2025 The Kubernetes Authors. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package main | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"os" | ||
|
||
"golang.org/x/sync/errgroup" | ||
clusterinventoryv1alpha1 "sigs.k8s.io/cluster-inventory-api/apis/v1alpha1" | ||
|
||
corev1 "k8s.io/api/core/v1" | ||
apierrors "k8s.io/apimachinery/pkg/api/errors" | ||
"k8s.io/apimachinery/pkg/util/runtime" | ||
"k8s.io/client-go/kubernetes/scheme" | ||
|
||
ctrl "sigs.k8s.io/controller-runtime" | ||
ctrllog "sigs.k8s.io/controller-runtime/pkg/log" | ||
"sigs.k8s.io/controller-runtime/pkg/log/zap" | ||
"sigs.k8s.io/controller-runtime/pkg/manager" | ||
"sigs.k8s.io/controller-runtime/pkg/manager/signals" | ||
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server" | ||
"sigs.k8s.io/controller-runtime/pkg/reconcile" | ||
|
||
mcbuilder "sigs.k8s.io/multicluster-runtime/pkg/builder" | ||
mcmanager "sigs.k8s.io/multicluster-runtime/pkg/manager" | ||
mcreconcile "sigs.k8s.io/multicluster-runtime/pkg/reconcile" | ||
clusterinventoryapi "sigs.k8s.io/multicluster-runtime/providers/cluster-inventory-api" | ||
) | ||
|
||
func init() { | ||
runtime.Must(clusterinventoryv1alpha1.AddToScheme(scheme.Scheme)) | ||
} | ||
|
||
func main() { | ||
ctrllog.SetLogger(zap.New(zap.UseDevMode(true))) | ||
entryLog := ctrllog.Log.WithName("entrypoint") | ||
ctx := signals.SetupSignalHandler() | ||
|
||
// Start local manager to read the Cluster Inventory API objects. | ||
cfg, err := ctrl.GetConfig() | ||
if err != nil { | ||
entryLog.Error(err, "unable to get kubeconfig") | ||
os.Exit(1) | ||
} | ||
|
||
// Create the provider against the local manager. | ||
provider := clusterinventoryapi.New(clusterinventoryapi.Options{ | ||
ConsumerName: "cluster-inventory-api-consumer", | ||
}) | ||
if err != nil { | ||
entryLog.Error(err, "unable to create provider") | ||
os.Exit(1) | ||
} | ||
|
||
// Create a multi-cluster manager attached to the provider. | ||
entryLog.Info("Setting up local manager") | ||
mcMgr, err := mcmanager.New(cfg, provider, manager.Options{ | ||
LeaderElection: false, | ||
Metrics: metricsserver.Options{ | ||
BindAddress: "0", // only one can listen | ||
}, | ||
}) | ||
if err != nil { | ||
entryLog.Error(err, "unable to set up overall controller manager") | ||
os.Exit(1) | ||
} | ||
|
||
// Setting up the provider with multi-cluster manager. | ||
if err := provider.SetupWithManager(mcMgr); err != nil { | ||
entryLog.Error(err, "unable to set up provider with manager") | ||
os.Exit(1) | ||
} | ||
|
||
// Create a configmap controller in the multi-cluster manager. | ||
if err := mcbuilder.ControllerManagedBy(mcMgr). | ||
Named("multicluster-configmaps"). | ||
For(&corev1.ConfigMap{}). | ||
Complete(mcreconcile.Func( | ||
func(ctx context.Context, req mcreconcile.Request) (ctrl.Result, error) { | ||
log := ctrllog.FromContext(ctx).WithValues("cluster", req.ClusterName) | ||
log.Info("Reconciling ConfigMap") | ||
|
||
cl, err := mcMgr.GetCluster(ctx, req.ClusterName) | ||
if err != nil { | ||
return reconcile.Result{}, err | ||
} | ||
|
||
cm := &corev1.ConfigMap{} | ||
if err := cl.GetClient().Get(ctx, req.Request.NamespacedName, cm); err != nil { | ||
if apierrors.IsNotFound(err) { | ||
return reconcile.Result{}, nil | ||
} | ||
return reconcile.Result{}, err | ||
} | ||
|
||
log.Info("ConfigMap in cluster", "configmap", cm.Namespace+"/"+cm.Name, "cluster", req.ClusterName) | ||
|
||
return ctrl.Result{}, nil | ||
}, | ||
)); err != nil { | ||
entryLog.Error(err, "failed to build controller") | ||
os.Exit(1) | ||
} | ||
|
||
// Starting everything. | ||
g, ctx := errgroup.WithContext(ctx) | ||
g.Go(func() error { | ||
return ignoreCanceled(mcMgr.Start(ctx)) | ||
}) | ||
if err := g.Wait(); err != nil { | ||
entryLog.Error(err, "unable to start") | ||
os.Exit(1) | ||
} | ||
} | ||
|
||
func ignoreCanceled(err error) error { | ||
if errors.Is(err, context.Canceled) { | ||
return nil | ||
} | ||
return err | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
module sigs.k8s.io/multicluster-runtime/providers/cluster-inventory-api | ||
|
||
go 1.24.2 | ||
|
||
replace sigs.k8s.io/multicluster-runtime => ../.. | ||
|
||
require ( | ||
github.com/go-logr/logr v1.4.2 | ||
github.com/onsi/ginkgo/v2 v2.22.0 | ||
github.com/onsi/gomega v1.36.1 | ||
golang.org/x/sync v0.12.0 | ||
k8s.io/api v0.33.0 | ||
k8s.io/apimachinery v0.33.0 | ||
k8s.io/client-go v0.33.0 | ||
k8s.io/utils v0.0.0-20241210054802-24370beab758 | ||
sigs.k8s.io/cluster-inventory-api v0.0.0-20250318031555-c7c0594aa53b | ||
sigs.k8s.io/controller-runtime v0.21.0 | ||
sigs.k8s.io/multicluster-runtime v0.21.0-alpha.8 | ||
) | ||
|
||
require ( | ||
github.com/beorn7/perks v1.0.1 // indirect | ||
github.com/blang/semver/v4 v4.0.0 // indirect | ||
github.com/cespare/xxhash/v2 v2.3.0 // indirect | ||
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect | ||
github.com/emicklei/go-restful/v3 v3.12.2 // indirect | ||
github.com/evanphx/json-patch/v5 v5.9.11 // indirect | ||
github.com/fsnotify/fsnotify v1.7.0 // indirect | ||
github.com/fxamacker/cbor/v2 v2.7.0 // indirect | ||
github.com/go-logr/zapr v1.3.0 // indirect | ||
github.com/go-openapi/jsonpointer v0.21.1 // indirect | ||
github.com/go-openapi/jsonreference v0.21.0 // indirect | ||
github.com/go-openapi/swag v0.23.1 // indirect | ||
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect | ||
github.com/gogo/protobuf v1.3.2 // indirect | ||
github.com/google/btree v1.1.3 // indirect | ||
github.com/google/gnostic-models v0.6.9 // indirect | ||
github.com/google/go-cmp v0.7.0 // indirect | ||
github.com/google/pprof v0.0.0-20241029153458-d1b30febd7db // indirect | ||
github.com/google/uuid v1.6.0 // indirect | ||
github.com/josharian/intern v1.0.0 // indirect | ||
github.com/json-iterator/go v1.1.12 // indirect | ||
github.com/mailru/easyjson v0.9.0 // indirect | ||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect | ||
github.com/modern-go/reflect2 v1.0.2 // indirect | ||
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect | ||
github.com/pkg/errors v0.9.1 // indirect | ||
github.com/prometheus/client_golang v1.22.0 // indirect | ||
github.com/prometheus/client_model v0.6.1 // indirect | ||
github.com/prometheus/common v0.62.0 // indirect | ||
github.com/prometheus/procfs v0.15.1 // indirect | ||
github.com/spf13/pflag v1.0.5 // indirect | ||
github.com/x448/float16 v0.8.4 // indirect | ||
go.uber.org/multierr v1.11.0 // indirect | ||
go.uber.org/zap v1.27.0 // indirect | ||
golang.org/x/net v0.38.0 // indirect | ||
golang.org/x/oauth2 v0.28.0 // indirect | ||
golang.org/x/sys v0.31.0 // indirect | ||
golang.org/x/term v0.30.0 // indirect | ||
golang.org/x/text v0.23.0 // indirect | ||
golang.org/x/time v0.11.0 // indirect | ||
golang.org/x/tools v0.26.0 // indirect | ||
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect | ||
google.golang.org/protobuf v1.36.5 // indirect | ||
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect | ||
gopkg.in/inf.v0 v0.9.1 // indirect | ||
gopkg.in/yaml.v3 v3.0.1 // indirect | ||
k8s.io/apiextensions-apiserver v0.33.0 // indirect | ||
k8s.io/klog/v2 v2.130.1 // indirect | ||
k8s.io/kube-openapi v0.0.0-20250318190949-c8a335a9a2ff // indirect | ||
sigs.k8s.io/json v0.0.0-20241014173422-cfa47c3a1cc8 // indirect | ||
sigs.k8s.io/randfill v1.0.0 // indirect | ||
sigs.k8s.io/structured-merge-diff/v4 v4.6.0 // indirect | ||
sigs.k8s.io/yaml v1.4.0 // indirect | ||
) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.