Skip to content

Commit

Permalink
update sdk-go lib (open-cluster-management-io#357)
Browse files Browse the repository at this point in the history
Signed-off-by: Wei Liu <liuweixa@redhat.com>
  • Loading branch information
skeeey authored and qiujian16 committed Jan 30, 2024
1 parent 4ab47cf commit 0fee67d
Show file tree
Hide file tree
Showing 32 changed files with 1,732 additions and 22 deletions.
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ require (
k8s.io/utils v0.0.0-20240102154912-e7106e64919e
open-cluster-management.io/addon-framework v0.8.1-0.20240123051722-71f1b13cbb63
open-cluster-management.io/api v0.12.1-0.20240122084346-e7bd1bd9ea6a
open-cluster-management.io/sdk-go v0.0.0-20240129065956-3ff755820797
open-cluster-management.io/sdk-go v0.0.0-20240130025514-7385f9baadf0
sigs.k8s.io/about-api v0.0.0-20230306212818-bee4439972de
sigs.k8s.io/controller-runtime v0.16.2
sigs.k8s.io/kube-storage-version-migrator v0.0.6-0.20230721195810-5c8923c5ff96
)
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -454,8 +454,10 @@ open-cluster-management.io/addon-framework v0.8.1-0.20240123051722-71f1b13cbb63
open-cluster-management.io/addon-framework v0.8.1-0.20240123051722-71f1b13cbb63/go.mod h1:SBs6wF0Umzr5/miJb9p8uMaTDbcjphHHQLa76nXnbU8=
open-cluster-management.io/api v0.12.1-0.20240122084346-e7bd1bd9ea6a h1:NjIU3aN4JSJjTotHiOkOCqYaPGG2tNtm7BY/o9uPb8M=
open-cluster-management.io/api v0.12.1-0.20240122084346-e7bd1bd9ea6a/go.mod h1:vOz9InrJq1BDFEI51+OwAyq2M3tjYPY+1cnoQhMhIlE=
open-cluster-management.io/sdk-go v0.0.0-20240129065956-3ff755820797 h1:UgM7kMPxiGAtik/382oOYk2AaTCAWPmnILs39W9ojSk=
open-cluster-management.io/sdk-go v0.0.0-20240129065956-3ff755820797/go.mod h1:p3oaf+iu9ghMl4cBJXWXlDnUHVn+QxL90YLTve9bn/k=
open-cluster-management.io/sdk-go v0.0.0-20240130025514-7385f9baadf0 h1:A+l3SkDPWnRwK3+WE5MVMh7NBvDCKkhdA+AB7Tw/lRM=
open-cluster-management.io/sdk-go v0.0.0-20240130025514-7385f9baadf0/go.mod h1:p3oaf+iu9ghMl4cBJXWXlDnUHVn+QxL90YLTve9bn/k=
sigs.k8s.io/about-api v0.0.0-20230306212818-bee4439972de h1:31d+rrY+47FHwMo7KnN3MITFrOSLpTqvyGmIzz9FPZU=
sigs.k8s.io/about-api v0.0.0-20230306212818-bee4439972de/go.mod h1:M7zycezDHpiwNVyhTjtfVVeIp+cB06z9o/zTR7gM9F8=
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.28.0 h1:TgtAeesdhpm2SGwkQasmbeqDo8th5wOBA5h/AjTKA4I=
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.28.0/go.mod h1:VHVDI/KrK4fjnV61bE2g3sA7tiETLn8sooImelsCx3Y=
sigs.k8s.io/controller-runtime v0.16.2 h1:mwXAVuEk3EQf478PQwQ48zGOXvW27UJc8NHktQVuIPU=
Expand Down
63 changes: 63 additions & 0 deletions manifests/klusterlet/managed/clusterproperties.crd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
api-approved.kubernetes.io: "https://github.com/kubernetes/enhancements/pull/3084"
name: clusterproperties.about.k8s.io
spec:
group: about.k8s.io
names:
kind: ClusterProperty
listKind: ClusterPropertyList
plural: clusterproperties
singular: clusterproperty
scope: Cluster
versions:
- additionalPrinterColumns:
- jsonPath: .spec.value
name: value
type: string
- jsonPath: .metadata.creationTimestamp
name: age
type: date
name: v1alpha1
schema:
openAPIV3Schema:
description: ClusterProperty is the Schema for the clusterproperties API
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
of an object. Servers should convert recognized schemas to the latest
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
type: string
kind:
description: 'Kind is a string value representing the REST resource this
object represents. Servers may infer this from the endpoint the client
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
type: string
metadata:
type: object
spec:
description: ClusterPropertySpec defines the desired state of ClusterProperty
properties:
value:
description: ClusterProperty value
minLength: 1
type: string
required:
- value
type: object
status:
description: ClusterPropertyStatus defines the observed state of ClusterProperty
type: object
type: object
served: true
storage: true
subresources:
status: {}
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ var (
crdV1StaticFiles = []string{
"klusterlet/managed/0000_01_work.open-cluster-management.io_appliedmanifestworks.crd.yaml",
"klusterlet/managed/0000_02_clusters.open-cluster-management.io_clusterclaims.crd.yaml",
"klusterlet/managed/clusterproperties.crd.yaml",
}

crdV1beta1StaticFiles = []string{
Expand Down
39 changes: 34 additions & 5 deletions pkg/registration/spoke/managedcluster/claim_reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@ import (

"github.com/openshift/library-go/pkg/operator/events"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/selection"
"k8s.io/apimachinery/pkg/util/sets"

"k8s.io/klog/v2"
clusterv1alpha1listers "open-cluster-management.io/api/client/cluster/listers/cluster/v1alpha1"
clusterv1 "open-cluster-management.io/api/cluster/v1"
clusterv1alpha1 "open-cluster-management.io/api/cluster/v1alpha1"
ocmfeature "open-cluster-management.io/api/feature"
aboutv1alpha1 "sigs.k8s.io/about-api/pkg/apis/v1alpha1"
aboutv1alpha1listers "sigs.k8s.io/about-api/pkg/generated/listers/apis/v1alpha1"

"open-cluster-management.io/ocm/pkg/features"
)
Expand All @@ -24,6 +27,7 @@ const labelCustomizedOnly = "open-cluster-management.io/spoke-only"
type claimReconcile struct {
recorder events.Recorder
claimLister clusterv1alpha1listers.ClusterClaimLister
aboutLister aboutv1alpha1listers.ClusterPropertyLister
maxCustomClusterClaims int
}

Expand All @@ -45,6 +49,7 @@ func (r *claimReconcile) reconcile(ctx context.Context, cluster *clusterv1.Manag
// managed cluster on hub. Some of the customized claims might not be exposed once
// the total number of the claims exceeds the value of `cluster-claims-max`.
func (r *claimReconcile) exposeClaims(ctx context.Context, cluster *clusterv1.ManagedCluster) error {
logger := klog.FromContext(ctx)
var reservedClaims, customClaims []clusterv1.ManagedClusterClaim

// clusterClaim with label `open-cluster-management.io/spoke-only` will not be synced to managedCluster.Status at hub.
Expand All @@ -55,13 +60,37 @@ func (r *claimReconcile) exposeClaims(ctx context.Context, cluster *clusterv1.Ma
return fmt.Errorf("unable to list cluster claims: %w", err)
}

reservedClaimNames := sets.NewString(clusterv1alpha1.ReservedClusterClaimNames[:]...)
clusterProperties, err := r.aboutLister.ClusterProperties(metav1.NamespaceAll).List(labels.Everything())
if err != nil {
logger.Error(err, "failed to get cluster properties")
}

propertiesMap := map[string]*aboutv1alpha1.ClusterProperty{}
for _, property := range clusterProperties {
propertiesMap[property.Name] = property
}
// convert claim to properties
for _, clusterClaim := range clusterClaims {
// if the claim has the same name with the property, ignore it.
if _, ok := propertiesMap[clusterClaim.Name]; !ok {
propertiesMap[clusterClaim.Name] = &aboutv1alpha1.ClusterProperty{
ObjectMeta: metav1.ObjectMeta{
Name: clusterClaim.Name,
},
Spec: aboutv1alpha1.ClusterPropertySpec{
Value: clusterClaim.Spec.Value,
},
}
}
}

reservedClaimNames := sets.NewString(clusterv1alpha1.ReservedClusterClaimNames[:]...)
for _, property := range propertiesMap {
managedClusterClaim := clusterv1.ManagedClusterClaim{
Name: clusterClaim.Name,
Value: clusterClaim.Spec.Value,
Name: property.Name,
Value: property.Spec.Value,
}
if reservedClaimNames.Has(clusterClaim.Name) {
if reservedClaimNames.Has(property.Name) {
reservedClaims = append(reservedClaims, managedClusterClaim)
continue
}
Expand Down
15 changes: 12 additions & 3 deletions pkg/registration/spoke/managedcluster/status_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"k8s.io/apimachinery/pkg/util/errors"
"k8s.io/client-go/discovery"
corev1informers "k8s.io/client-go/informers/core/v1"
aboutv1alpha1informer "sigs.k8s.io/about-api/pkg/generated/informers/externalversions/apis/v1alpha1"

clientset "open-cluster-management.io/api/client/cluster/clientset/versioned"
clusterv1informer "open-cluster-management.io/api/client/cluster/informers/externalversions/cluster/v1"
Expand Down Expand Up @@ -46,6 +47,7 @@ func NewManagedClusterStatusController(
hubClusterInformer clusterv1informer.ManagedClusterInformer,
managedClusterDiscoveryClient discovery.DiscoveryInterface,
claimInformer clusterv1alpha1informer.ClusterClaimInformer,
propertyInformer aboutv1alpha1informer.ClusterPropertyInformer,
nodeInformer corev1informers.NodeInformer,
maxCustomClusterClaims int,
resyncInterval time.Duration,
Expand All @@ -56,13 +58,14 @@ func NewManagedClusterStatusController(
hubClusterInformer,
managedClusterDiscoveryClient,
claimInformer,
propertyInformer,
nodeInformer,
maxCustomClusterClaims,
recorder,
)

return factory.New().
WithInformers(hubClusterInformer.Informer(), nodeInformer.Informer(), claimInformer.Informer()).
WithInformers(hubClusterInformer.Informer(), nodeInformer.Informer(), claimInformer.Informer(), propertyInformer.Informer()).
WithSync(c.sync).
ResyncEvery(resyncInterval).
ToController("ManagedClusterStatusController", recorder)
Expand All @@ -74,6 +77,7 @@ func newManagedClusterStatusController(
hubClusterInformer clusterv1informer.ManagedClusterInformer,
managedClusterDiscoveryClient discovery.DiscoveryInterface,
claimInformer clusterv1alpha1informer.ClusterClaimInformer,
propertyInformer aboutv1alpha1informer.ClusterPropertyInformer,
nodeInformer corev1informers.NodeInformer,
maxCustomClusterClaims int,
recorder events.Recorder) *managedClusterStatusController {
Expand All @@ -84,8 +88,13 @@ func newManagedClusterStatusController(
hubClusterClient.ClusterV1().ManagedClusters()),
reconcilers: []statusReconcile{
&joiningReconcile{recorder: recorder},
&resoureReconcile{managedClusterDiscoveryClient: managedClusterDiscoveryClient, nodeLister: nodeInformer.Lister()},
&claimReconcile{claimLister: claimInformer.Lister(), recorder: recorder, maxCustomClusterClaims: maxCustomClusterClaims},
&resoureReconcile{
managedClusterDiscoveryClient: managedClusterDiscoveryClient, nodeLister: nodeInformer.Lister()},
&claimReconcile{
claimLister: claimInformer.Lister(),
aboutLister: propertyInformer.Lister(),
recorder: recorder,
maxCustomClusterClaims: maxCustomClusterClaims},
},
hubClusterLister: hubClusterInformer.Lister(),
}
Expand Down
12 changes: 11 additions & 1 deletion pkg/registration/spoke/spokeagent.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@ import (
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/klog/v2"

addonclient "open-cluster-management.io/api/client/addon/clientset/versioned"
addoninformers "open-cluster-management.io/api/client/addon/informers/externalversions"
clusterv1client "open-cluster-management.io/api/client/cluster/clientset/versioned"
clusterv1informers "open-cluster-management.io/api/client/cluster/informers/externalversions"
clusterv1 "open-cluster-management.io/api/cluster/v1"
ocmfeature "open-cluster-management.io/api/feature"
aboutclient "sigs.k8s.io/about-api/pkg/generated/clientset/versioned"
aboutinformers "sigs.k8s.io/about-api/pkg/generated/informers/externalversions"

commonoptions "open-cluster-management.io/ocm/pkg/common/options"
"open-cluster-management.io/ocm/pkg/features"
Expand Down Expand Up @@ -109,13 +110,19 @@ func (o *SpokeAgentConfig) RunSpokeAgent(ctx context.Context, controllerContext
return err
}

aboutClient, err := aboutclient.NewForConfig(spokeClientConfig)
if err != nil {
return err
}

return o.RunSpokeAgentWithSpokeInformers(
ctx,
kubeConfig,
spokeClientConfig,
spokeKubeClient,
informers.NewSharedInformerFactory(spokeKubeClient, 10*time.Minute),
clusterv1informers.NewSharedInformerFactory(spokeClusterClient, 10*time.Minute),
aboutinformers.NewSharedInformerFactory(aboutClient, 10*time.Minute),
controllerContext.EventRecorder,
)
}
Expand All @@ -125,6 +132,7 @@ func (o *SpokeAgentConfig) RunSpokeAgentWithSpokeInformers(ctx context.Context,
spokeKubeClient kubernetes.Interface,
spokeKubeInformerFactory informers.SharedInformerFactory,
spokeClusterInformerFactory clusterv1informers.SharedInformerFactory,
aboutInformerFactory aboutinformers.SharedInformerFactory,
recorder events.Recorder) error {
logger := klog.FromContext(ctx)
logger.Info("Cluster name and agent ID", "clusterName", o.agentOptions.SpokeClusterName, "agentID", o.agentOptions.AgentID)
Expand Down Expand Up @@ -378,6 +386,7 @@ func (o *SpokeAgentConfig) RunSpokeAgentWithSpokeInformers(ctx context.Context,
hubClusterInformerFactory.Cluster().V1().ManagedClusters(),
spokeKubeClient.Discovery(),
spokeClusterInformerFactory.Cluster().V1alpha1().ClusterClaims(),
aboutInformerFactory.About().V1alpha1().ClusterProperties(),
spokeKubeInformerFactory.Core().V1().Nodes(),
o.registrationOption.MaxCustomClusterClaims,
o.registrationOption.ClusterHealthCheckPeriod,
Expand Down Expand Up @@ -419,6 +428,7 @@ func (o *SpokeAgentConfig) RunSpokeAgentWithSpokeInformers(ctx context.Context,
go spokeKubeInformerFactory.Start(ctx.Done())
if features.SpokeMutableFeatureGate.Enabled(ocmfeature.ClusterClaim) {
go spokeClusterInformerFactory.Start(ctx.Done())
go aboutInformerFactory.Start(ctx.Done())
}

go clientCertForHubController.Run(ctx, 1)
Expand Down
13 changes: 7 additions & 6 deletions test/integration/registration/integration_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,14 @@ var startHub func()

var CRDPaths = []string{
// hub
"./vendor/open-cluster-management.io/api/cluster/v1/0000_00_clusters.open-cluster-management.io_managedclusters.crd.yaml",
"./vendor/open-cluster-management.io/api/work/v1/0000_00_work.open-cluster-management.io_manifestworks.crd.yaml",
"./vendor/open-cluster-management.io/api/addon/v1alpha1/0000_01_addon.open-cluster-management.io_managedclusteraddons.crd.yaml",
"./vendor/open-cluster-management.io/api/cluster/v1beta2/0000_00_clusters.open-cluster-management.io_managedclustersets.crd.yaml",
"./vendor/open-cluster-management.io/api/cluster/v1beta2/0000_01_clusters.open-cluster-management.io_managedclustersetbindings.crd.yaml",
"./manifests/cluster-manager/hub/0000_00_clusters.open-cluster-management.io_managedclusters.crd.yaml",
"./manifests/cluster-manager/hub/0000_00_work.open-cluster-management.io_manifestworks.crd.yaml",
"./manifests/cluster-manager/hub/0000_01_addon.open-cluster-management.io_managedclusteraddons.crd.yaml",
"./manifests/cluster-manager/hub/0000_00_clusters.open-cluster-management.io_managedclustersets.crd.yaml",
"./manifests/cluster-manager/hub/0000_01_clusters.open-cluster-management.io_managedclustersetbindings.crd.yaml",
// spoke
"./vendor/open-cluster-management.io/api/cluster/v1alpha1/0000_02_clusters.open-cluster-management.io_clusterclaims.crd.yaml",
"./manifests/klusterlet/managed/0000_02_clusters.open-cluster-management.io_clusterclaims.crd.yaml",
"./manifests/klusterlet/managed/clusterproperties.crd.yaml",
}

func runAgent(name string, opt *spoke.SpokeAgentOptions, commOption *commonoptions.AgentOptions, cfg *rest.Config) context.CancelFunc {
Expand Down
13 changes: 12 additions & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1578,7 +1578,7 @@ open-cluster-management.io/api/utils/work/v1/workapplier
open-cluster-management.io/api/utils/work/v1/workvalidator
open-cluster-management.io/api/work/v1
open-cluster-management.io/api/work/v1alpha1
# open-cluster-management.io/sdk-go v0.0.0-20240129065956-3ff755820797
# open-cluster-management.io/sdk-go v0.0.0-20240130025514-7385f9baadf0
## explicit; go 1.21
open-cluster-management.io/sdk-go/pkg/apis/cluster/v1alpha1
open-cluster-management.io/sdk-go/pkg/apis/cluster/v1beta1
Expand All @@ -1600,6 +1600,17 @@ open-cluster-management.io/sdk-go/pkg/cloudevents/work/payload
open-cluster-management.io/sdk-go/pkg/cloudevents/work/utils
open-cluster-management.io/sdk-go/pkg/cloudevents/work/watcher
open-cluster-management.io/sdk-go/pkg/patcher
# sigs.k8s.io/about-api v0.0.0-20230306212818-bee4439972de
## explicit; go 1.18
sigs.k8s.io/about-api/pkg/apis/v1alpha1
sigs.k8s.io/about-api/pkg/generated/clientset/versioned
sigs.k8s.io/about-api/pkg/generated/clientset/versioned/scheme
sigs.k8s.io/about-api/pkg/generated/clientset/versioned/typed/apis/v1alpha1
sigs.k8s.io/about-api/pkg/generated/informers/externalversions
sigs.k8s.io/about-api/pkg/generated/informers/externalversions/apis
sigs.k8s.io/about-api/pkg/generated/informers/externalversions/apis/v1alpha1
sigs.k8s.io/about-api/pkg/generated/informers/externalversions/internalinterfaces
sigs.k8s.io/about-api/pkg/generated/listers/apis/v1alpha1
# sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.28.0
## explicit; go 1.20
sigs.k8s.io/apiserver-network-proxy/konnectivity-client/pkg/client
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 0fee67d

Please sign in to comment.