Skip to content

Commit

Permalink
refactor basecontroller with sdk-go and remove certrotation to sdk-go
Browse files Browse the repository at this point in the history
Signed-off-by: Zhiwei Yin <[email protected]>
  • Loading branch information
zhiweiyin318 committed Jun 20, 2024
1 parent 660e21b commit fbabef3
Show file tree
Hide file tree
Showing 138 changed files with 32,706 additions and 1,950 deletions.
2 changes: 1 addition & 1 deletion examples/helloworld_agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ import (
"k8s.io/client-go/tools/cache"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/klog/v2"
"open-cluster-management.io/addon-framework/pkg/basecontroller/factory"
cmdfactory "open-cluster-management.io/addon-framework/pkg/cmd/factory"
"open-cluster-management.io/addon-framework/pkg/lease"
"open-cluster-management.io/addon-framework/pkg/version"
addonv1alpha1client "open-cluster-management.io/api/client/addon/clientset/versioned"
"open-cluster-management.io/sdk-go/pkg/basecontroller/factory"
)

func NewAgentCommand(addonName string) *cobra.Command {
Expand Down
16 changes: 10 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ require (
k8s.io/klog/v2 v2.120.1
k8s.io/utils v0.0.0-20240310230437-4693a0247e57
open-cluster-management.io/api v0.13.0
open-cluster-management.io/sdk-go v0.13.1-0.20240416062924-20307e6fe090
open-cluster-management.io/sdk-go v0.13.1-0.20240614070053-a01091a14da7
sigs.k8s.io/controller-runtime v0.17.2
)

Expand All @@ -41,8 +41,10 @@ require (
github.com/bwmarrin/snowflake v0.3.0 // indirect
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/cloudevents/sdk-go/protocol/kafka_confluent/v2 v2.0.0-20240413090539-7fef29478991 // indirect
github.com/cloudevents/sdk-go/protocol/mqtt_paho/v2 v2.0.0-20231030012137-0836a524e995 // indirect
github.com/cloudevents/sdk-go/v2 v2.15.2 // indirect
github.com/cloudevents/sdk-go/v2 v2.15.3-0.20240329120647-e6a74efbacbf // indirect
github.com/confluentinc/confluent-kafka-go/v2 v2.3.0 // indirect
github.com/coreos/go-semver v0.3.1 // indirect
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
github.com/cyphar/filepath-securejoin v0.2.4 // indirect
Expand Down Expand Up @@ -78,6 +80,8 @@ require (
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/moby/patternmatcher v0.6.0 // indirect
github.com/moby/sys/sequential v0.5.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
Expand Down Expand Up @@ -109,13 +113,13 @@ require (
go.opentelemetry.io/proto/otlp v1.0.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.26.0 // indirect
golang.org/x/crypto v0.19.0 // indirect
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 // indirect
golang.org/x/net v0.21.0 // indirect
golang.org/x/net v0.23.0 // indirect
golang.org/x/oauth2 v0.16.0 // indirect
golang.org/x/sync v0.6.0 // indirect
golang.org/x/sys v0.17.0 // indirect
golang.org/x/term v0.17.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/term v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.3.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
Expand Down
66 changes: 54 additions & 12 deletions go.sum

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pkg/addonmanager/addontesting/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
clusterv1 "open-cluster-management.io/api/cluster/v1"
workapiv1 "open-cluster-management.io/api/work/v1"

"open-cluster-management.io/addon-framework/pkg/basecontroller/events"
"open-cluster-management.io/sdk-go/pkg/basecontroller/events"
)

type FakeSyncContext struct {
Expand Down
2 changes: 1 addition & 1 deletion pkg/addonmanager/base_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import (
"open-cluster-management.io/addon-framework/pkg/addonmanager/controllers/cmamanagedby"
"open-cluster-management.io/addon-framework/pkg/addonmanager/controllers/registration"
"open-cluster-management.io/addon-framework/pkg/agent"
"open-cluster-management.io/addon-framework/pkg/basecontroller/factory"
"open-cluster-management.io/addon-framework/pkg/utils"
"open-cluster-management.io/sdk-go/pkg/basecontroller/factory"
)

// BaseAddonManagerImpl is the base implementation of BaseAddonManager
Expand Down
62 changes: 44 additions & 18 deletions pkg/addonmanager/cloudevents/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ package cloudevents

import (
"context"
"fmt"
workclientset "open-cluster-management.io/api/client/work/clientset/versioned"
cloudeventswork "open-cluster-management.io/sdk-go/pkg/cloudevents/work"
"open-cluster-management.io/sdk-go/pkg/cloudevents/work/store"
"time"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand All @@ -20,7 +24,8 @@ import (

"open-cluster-management.io/addon-framework/pkg/addonmanager"
"open-cluster-management.io/addon-framework/pkg/index"
cloudeventswork "open-cluster-management.io/sdk-go/pkg/cloudevents/work"
"open-cluster-management.io/sdk-go/pkg/cloudevents/constants"
"open-cluster-management.io/sdk-go/pkg/cloudevents/generic"
"open-cluster-management.io/sdk-go/pkg/cloudevents/work/source/codec"
)

Expand All @@ -44,11 +49,37 @@ func (a *cloudeventsAddonManager) Start(ctx context.Context) error {
// ManifestWork client that implements the ManifestWorkInterface and ManifestWork informer based on different
// driver configuration.
// Refer to Event Based Manifestwork proposal in enhancements repo to get more details.
_, clientConfig, err := cloudeventswork.NewConfigLoader(a.options.WorkDriver, a.options.WorkDriverConfig).
WithKubeConfig(a.GetConfig()).
LoadConfig()
if err != nil {
return err
var workClient workclientset.Interface
var watcherStore *store.SourceInformerWatcherStore
var err error
switch a.options.WorkDriver {
case "kube":
workClient, err = workclientset.NewForConfig(config)
if err != nil {
return err
}
case constants.ConfigTypeGRPC, constants.ConfigTypeMQTT:
watcherStore = store.NewSourceInformerWatcherStore(ctx)

_, clientConfig, err := generic.NewConfigLoader(a.options.WorkDriver, a.options.WorkDriverConfig).
LoadConfig()
if err != nil {
return err
}

clientHolder, err := cloudeventswork.NewClientHolderBuilder(clientConfig).
WithClientID(a.options.CloudEventsClientID).
WithSourceID(a.options.SourceID).
WithCodecs(codec.NewManifestBundleCodec()).
WithWorkClientWatcherStore(watcherStore).
NewSourceClientHolder(ctx)
if err != nil {
return err
}

workClient = clientHolder.WorkInterface()
default:
return fmt.Errorf("unsupported work driver: %s", a.options.WorkDriver)
}

// we need a separated filtered manifestwork informers so we only watch the manifestworks that manifestworkreplicaset cares.
Expand All @@ -68,16 +99,6 @@ func (a *cloudeventsAddonManager) Start(ctx context.Context) error {
},
)

clientHolder, err := cloudeventswork.NewClientHolderBuilder(clientConfig).
WithClientID(a.options.CloudEventsClientID).
WithSourceID(a.options.SourceID).
WithInformerConfig(10*time.Minute, workInformOption).
WithCodecs(codec.NewManifestBundleCodec()).
NewSourceClientHolder(ctx)
if err != nil {
return err
}

kubeClient, err := kubernetes.NewForConfig(config)
if err != nil {
return err
Expand Down Expand Up @@ -117,8 +138,13 @@ func (a *cloudeventsAddonManager) Start(ctx context.Context) error {
}),
)

workClient := clientHolder.WorkInterface()
workInformers := clientHolder.ManifestWorkInformer()
factory := workinformers.NewSharedInformerFactoryWithOptions(workClient, 30*time.Minute, workInformOption)
workInformers := factory.Work().V1().ManifestWorks()

// For cloudevents work client, we use the informer store as the client store
if watcherStore != nil {
watcherStore.SetStore(workInformers.Informer().GetStore())
}

// addonDeployController
err = workInformers.Informer().AddIndexers(
Expand Down
3 changes: 1 addition & 2 deletions pkg/addonmanager/cloudevents/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package cloudevents

import (
"github.com/spf13/cobra"
cloudeventswork "open-cluster-management.io/sdk-go/pkg/cloudevents/work"
)

// CloudEventsOptions defines the flags for addon manager
Expand All @@ -17,7 +16,7 @@ type CloudEventsOptions struct {
func NewCloudEventsOptions() *CloudEventsOptions {
return &CloudEventsOptions{
// set default work driver to kube
WorkDriver: cloudeventswork.ConfigTypeKube,
WorkDriver: "kube",
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/addonmanager/controllers/addonconfig/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ import (
"k8s.io/client-go/dynamic/dynamiclister"
"k8s.io/client-go/tools/cache"
"k8s.io/client-go/util/workqueue"
"open-cluster-management.io/addon-framework/pkg/basecontroller/factory"
"open-cluster-management.io/addon-framework/pkg/index"
"open-cluster-management.io/addon-framework/pkg/utils"
addonapiv1alpha1 "open-cluster-management.io/api/addon/v1alpha1"
addonv1alpha1client "open-cluster-management.io/api/client/addon/clientset/versioned"
addoninformerv1alpha1 "open-cluster-management.io/api/client/addon/informers/externalversions/addon/v1alpha1"
addonlisterv1alpha1 "open-cluster-management.io/api/client/addon/listers/addon/v1alpha1"
"open-cluster-management.io/sdk-go/pkg/basecontroller/factory"
"open-cluster-management.io/sdk-go/pkg/patcher"
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/addonmanager/controllers/agentdeploy/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ import (

"open-cluster-management.io/addon-framework/pkg/addonmanager/constants"
"open-cluster-management.io/addon-framework/pkg/agent"
"open-cluster-management.io/addon-framework/pkg/basecontroller/factory"
"open-cluster-management.io/addon-framework/pkg/index"
"open-cluster-management.io/sdk-go/pkg/basecontroller/factory"
)

const (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
workapiv1 "open-cluster-management.io/api/work/v1"

"open-cluster-management.io/addon-framework/pkg/agent"
"open-cluster-management.io/addon-framework/pkg/basecontroller/factory"
"open-cluster-management.io/sdk-go/pkg/basecontroller/factory"
)

type defaultHookSyncer struct {
Expand Down
2 changes: 1 addition & 1 deletion pkg/addonmanager/controllers/agentdeploy/default_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
workapiv1 "open-cluster-management.io/api/work/v1"

"open-cluster-management.io/addon-framework/pkg/agent"
"open-cluster-management.io/addon-framework/pkg/basecontroller/factory"
"open-cluster-management.io/sdk-go/pkg/basecontroller/factory"
)

type defaultSyncer struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (

"open-cluster-management.io/addon-framework/pkg/addonmanager/constants"
"open-cluster-management.io/addon-framework/pkg/agent"
"open-cluster-management.io/addon-framework/pkg/basecontroller/factory"
"open-cluster-management.io/addon-framework/pkg/utils"
"open-cluster-management.io/sdk-go/pkg/basecontroller/factory"
)

type healthCheckSyncer struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

"open-cluster-management.io/addon-framework/pkg/addonmanager/constants"
"open-cluster-management.io/addon-framework/pkg/agent"
"open-cluster-management.io/addon-framework/pkg/basecontroller/factory"
"open-cluster-management.io/sdk-go/pkg/basecontroller/factory"
)

type hostedHookSyncer struct {
Expand Down
2 changes: 1 addition & 1 deletion pkg/addonmanager/controllers/agentdeploy/hosted_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

"open-cluster-management.io/addon-framework/pkg/addonmanager/constants"
"open-cluster-management.io/addon-framework/pkg/agent"
"open-cluster-management.io/addon-framework/pkg/basecontroller/factory"
"open-cluster-management.io/sdk-go/pkg/basecontroller/factory"
)

type hostedSyncer struct {
Expand Down
2 changes: 1 addition & 1 deletion pkg/addonmanager/controllers/certificate/csrapprove.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
clusterv1 "open-cluster-management.io/api/cluster/v1"

"open-cluster-management.io/addon-framework/pkg/agent"
"open-cluster-management.io/addon-framework/pkg/basecontroller/factory"
"open-cluster-management.io/sdk-go/pkg/basecontroller/factory"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion pkg/addonmanager/controllers/certificate/csrsign.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
clusterv1 "open-cluster-management.io/api/cluster/v1"

"open-cluster-management.io/addon-framework/pkg/agent"
"open-cluster-management.io/addon-framework/pkg/basecontroller/factory"
"open-cluster-management.io/sdk-go/pkg/basecontroller/factory"
)

// csrApprovingController auto approve the renewal CertificateSigningRequests for an accepted spoke cluster on the hub.
Expand Down
2 changes: 1 addition & 1 deletion pkg/addonmanager/controllers/cmaconfig/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ import (
addonlisterv1alpha1 "open-cluster-management.io/api/client/addon/listers/addon/v1alpha1"
"open-cluster-management.io/sdk-go/pkg/patcher"

"open-cluster-management.io/addon-framework/pkg/basecontroller/factory"
"open-cluster-management.io/addon-framework/pkg/index"
"open-cluster-management.io/addon-framework/pkg/utils"
"open-cluster-management.io/sdk-go/pkg/basecontroller/factory"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion pkg/addonmanager/controllers/cmamanagedby/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"open-cluster-management.io/sdk-go/pkg/patcher"

"open-cluster-management.io/addon-framework/pkg/agent"
"open-cluster-management.io/addon-framework/pkg/basecontroller/factory"
"open-cluster-management.io/sdk-go/pkg/basecontroller/factory"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion pkg/addonmanager/controllers/registration/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import (
"open-cluster-management.io/sdk-go/pkg/patcher"

"open-cluster-management.io/addon-framework/pkg/agent"
"open-cluster-management.io/addon-framework/pkg/basecontroller/factory"
"open-cluster-management.io/addon-framework/pkg/utils"
"open-cluster-management.io/sdk-go/pkg/basecontroller/factory"
)

// addonRegistrationController reconciles instances of ManagedClusterAddon on the hub.
Expand Down
Loading

0 comments on commit fbabef3

Please sign in to comment.