Skip to content

Commit

Permalink
Cleanup constants
Browse files Browse the repository at this point in the history
Signed-off-by: Tamal Saha <[email protected]>
  • Loading branch information
tamalsaha committed Mar 2, 2024
1 parent 96f0248 commit aa7906b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 19 deletions.
6 changes: 6 additions & 0 deletions apis/fluxcd/v1alpha1/fluxcdconfig_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ import (
"k8s.io/apimachinery/pkg/runtime"
)

const (
ResourceKindFluxCDConfig = "FluxCDConfig"
ResourceFluxCDConfig = "fluxcdconfig"
ResourceFluxCDConfigs = "fluxcdconfigs"
)

// FluxCDConfigSpec defines the desired state of FluxCDConfig
type FluxCDConfigSpec struct {
InstallCRDs bool `json:"installCRDs"`
Expand Down
17 changes: 4 additions & 13 deletions pkg/manager/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (
"context"
"fmt"

fluxcdv1alpha1 "github.com/kluster-manager/fluxcd-addon/apis/fluxcd/v1alpha1"

"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/types"
"open-cluster-management.io/addon-framework/pkg/addonfactory"
Expand All @@ -31,17 +33,6 @@ import (
"sigs.k8s.io/yaml"
)

const (
// FluxCDConfigVersion defines the API version used for FluxCDConfigs.
FluxCDConfigVersion = "v1alpha1"

// FluxCDConfigResource is the resource name for FluxCDConfig objects.
FluxCDConfigResource = "fluxcdconfigs"

// FluxCDConfigGroup is the group name for FluxCDConfig objects.
FluxCDConfigGroup = "fluxcd.open-cluster-management.io"
)

// GetConfigValues returns a function that retrieves and transforms configuration values from
// FluxCDConfig objects. The function fetches configuration references from a ManagedClusterAddOn,
// reads corresponding FluxCDConfig objects, extracts their specifications, and converts them into
Expand All @@ -50,8 +41,8 @@ func GetConfigValues(kc client.Client) addonfactory.GetValuesFunc {
return func(cluster *clusterv1.ManagedCluster, addon *v1alpha1.ManagedClusterAddOn) (addonfactory.Values, error) {
overrideValues := addonfactory.Values{}
for _, refConfig := range addon.Status.ConfigReferences {
if refConfig.ConfigGroupResource.Group != FluxCDConfigGroup ||
refConfig.ConfigGroupResource.Resource != FluxCDConfigResource {
if refConfig.ConfigGroupResource.Group != fluxcdv1alpha1.GroupVersion.Group ||
refConfig.ConfigGroupResource.Resource != fluxcdv1alpha1.ResourceFluxCDConfigs {
continue
}

Expand Down
9 changes: 3 additions & 6 deletions pkg/manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@ import (
"context"
"embed"

fluxapi1alpha1 "github.com/kluster-manager/fluxcd-addon/apis/fluxcd/v1alpha1"
fluxcdv1alpha1 "github.com/kluster-manager/fluxcd-addon/apis/fluxcd/v1alpha1"

"github.com/spf13/cobra"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/client-go/rest"
"k8s.io/component-base/version"
Expand Down Expand Up @@ -55,7 +54,7 @@ const (
var scheme = runtime.NewScheme()

func init() {
utilruntime.Must(fluxapi1alpha1.AddToScheme(scheme))
utilruntime.Must(fluxcdv1alpha1.AddToScheme(scheme))
}

// NewManagerCommand creates a command for starting the addon manager controller.
Expand Down Expand Up @@ -86,9 +85,7 @@ func runManagerController(ctx context.Context, kubeConfig *rest.Config) error {

// Initialize the agent addon factory and configure it.
agent, err := addonfactory.NewAgentAddonFactory(AddonName, FS, AgentManifestsDir).
WithConfigGVRs(
schema.GroupVersionResource{Group: FluxCDConfigGroup, Version: FluxCDConfigVersion, Resource: FluxCDConfigResource},
).
WithConfigGVRs(fluxcdv1alpha1.GroupVersion.WithResource(fluxcdv1alpha1.ResourceFluxCDConfigs)).
WithGetValuesFuncs(GetConfigValues(kubeClient)).
WithAgentHealthProber(agentHealthProber()).
WithAgentInstallNamespace(func(addon *v1alpha1.ManagedClusterAddOn) string { return AgentInstallNamespace }).
Expand Down

0 comments on commit aa7906b

Please sign in to comment.