Skip to content
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

Add agentRegistrationOptions #9

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions pkg/manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"k8s.io/klog/v2"
"open-cluster-management.io/addon-framework/pkg/addonfactory"
"open-cluster-management.io/addon-framework/pkg/addonmanager"
"open-cluster-management.io/addon-framework/pkg/agent"
cmdfactory "open-cluster-management.io/addon-framework/pkg/cmd/factory"
"open-cluster-management.io/api/addon/v1alpha1"
_ "open-cluster-management.io/api/addon/v1alpha1"
Expand All @@ -43,6 +44,8 @@ const (
// AddonName represents the name of the FluxCD addon.
AddonName = "fluxcd-addon"

AgentName = "fluxcd-addon"

// AgentManifestsDir is the directory containing Flux2 agent-manifests.
AgentManifestsDir = "agent-manifests/flux2"

Expand All @@ -68,6 +71,16 @@ func NewManagerCommand() *cobra.Command {
return cmd
}

func NewRegistrationOption(addonName, agentName string) *agent.RegistrationOption {
return &agent.RegistrationOption{
CSRConfigurations: agent.KubeClientSignerConfigurations(addonName, agentName),
CSRApproveCheck: agent.ApprovalAllCSRs,
AgentInstallNamespace: func(addon *v1alpha1.ManagedClusterAddOn) (string, error) {
return AgentInstallNamespace, nil
},
}
}

// runManagerController initializes and runs the addon manager controller.
// It sets up the required Kubernetes client, agent, and manager to manage the addon.
func runManagerController(ctx context.Context, kubeConfig *rest.Config) error {
Expand All @@ -83,10 +96,12 @@ func runManagerController(ctx context.Context, kubeConfig *rest.Config) error {
return err
}

registrationOption := NewRegistrationOption(AddonName, AgentName)
// Initialize the agent addon factory and configure it.
agent, err := addonfactory.NewAgentAddonFactory(AddonName, FS, AgentManifestsDir).
WithConfigGVRs(fluxcdv1alpha1.GroupVersion.WithResource(fluxcdv1alpha1.ResourceFluxCDConfigs)).
WithGetValuesFuncs(GetConfigValues(kubeClient)).
WithAgentRegistrationOption(registrationOption).
WithAgentHealthProber(agentHealthProber()).
WithAgentInstallNamespace(func(addon *v1alpha1.ManagedClusterAddOn) (string, error) { return AgentInstallNamespace, nil }).
BuildHelmAgentAddon()
Expand Down
Loading