Skip to content

Commit

Permalink
operator: depend on aggregator.Interface for DI
Browse files Browse the repository at this point in the history
Signed-off-by: Mohamed Awnallah <mohamedmohey2352@gmail.com>
  • Loading branch information
mohamedawnallah committed Sep 27, 2024
1 parent 4c8bcd4 commit 6c490dc
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 13 deletions.
12 changes: 6 additions & 6 deletions operator/pkg/karmadaresource/apiservice/apiservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ func init() {
}

// EnsureAggregatedAPIService creates aggregated APIService and a service
func EnsureAggregatedAPIService(aggregatorClient *aggregator.Clientset, client clientset.Interface, karmadaControlPlaneServiceName, karmadaControlPlaneNamespace, hostClusterServiceName, hostClusterNamespace, caBundle string) error {
func EnsureAggregatedAPIService(aggregatorClient aggregator.Interface, client clientset.Interface, karmadaControlPlaneServiceName, karmadaControlPlaneNamespace, hostClusterServiceName, hostClusterNamespace, caBundle string) error {
if err := aggregatedApiserverService(client, karmadaControlPlaneServiceName, karmadaControlPlaneNamespace, hostClusterServiceName, hostClusterNamespace); err != nil {
return err
}

return aggregatedAPIService(aggregatorClient, karmadaControlPlaneServiceName, karmadaControlPlaneNamespace, caBundle)
}

func aggregatedAPIService(client *aggregator.Clientset, karmadaControlPlaneServiceName, karmadaControlPlaneNamespace, caBundle string) error {
func aggregatedAPIService(client aggregator.Interface, karmadaControlPlaneServiceName, karmadaControlPlaneNamespace, caBundle string) error {
apiServiceBytes, err := util.ParseTemplate(KarmadaAggregatedAPIService, struct {
Namespace string
ServiceName string
Expand Down Expand Up @@ -101,15 +101,15 @@ func aggregatedApiserverService(client clientset.Interface, karmadaControlPlaneS
}

// EnsureMetricsAdapterAPIService creates APIService and a service for karmada-metrics-adapter
func EnsureMetricsAdapterAPIService(aggregatorClient *aggregator.Clientset, client clientset.Interface, karmadaControlPlaneServiceName, karmadaControlPlaneNamespace, hostClusterServiceName, hostClusterNamespace, caBundle string) error {
func EnsureMetricsAdapterAPIService(aggregatorClient aggregator.Interface, client clientset.Interface, karmadaControlPlaneServiceName, karmadaControlPlaneNamespace, hostClusterServiceName, hostClusterNamespace, caBundle string) error {
if err := karmadaMetricsAdapterService(client, karmadaControlPlaneServiceName, karmadaControlPlaneNamespace, hostClusterServiceName, hostClusterNamespace); err != nil {
return err
}

return karmadaMetricsAdapterAPIService(aggregatorClient, karmadaControlPlaneServiceName, karmadaControlPlaneNamespace, caBundle)
}

func karmadaMetricsAdapterAPIService(client *aggregator.Clientset, karmadaControlPlaneServiceName, karmadaControlPlaneNamespace, caBundle string) error {
func karmadaMetricsAdapterAPIService(client aggregator.Interface, karmadaControlPlaneServiceName, karmadaControlPlaneNamespace, caBundle string) error {
for _, gv := range constants.KarmadaMetricsAdapterAPIServices {
// The APIService name to metrics adapter is "$version.$group"
apiServiceName := fmt.Sprintf("%s.%s", gv.Version, gv.Group)
Expand Down Expand Up @@ -171,15 +171,15 @@ func karmadaMetricsAdapterService(client clientset.Interface, karmadaControlPlan
}

// EnsureSearchAPIService creates APIService and a service for karmada-metrics-adapter
func EnsureSearchAPIService(aggregatorClient *aggregator.Clientset, client clientset.Interface, karmadaControlPlaneServiceName, karmadaControlPlaneNamespace, hostClusterServiceName, hostClusterNamespace, caBundle string) error {
func EnsureSearchAPIService(aggregatorClient aggregator.Interface, client clientset.Interface, karmadaControlPlaneServiceName, karmadaControlPlaneNamespace, hostClusterServiceName, hostClusterNamespace, caBundle string) error {
if err := karmadaSearchService(client, karmadaControlPlaneServiceName, karmadaControlPlaneNamespace, hostClusterServiceName, hostClusterNamespace); err != nil {
return err
}

return karmadaSearchAPIService(aggregatorClient, karmadaControlPlaneServiceName, karmadaControlPlaneNamespace, caBundle)
}

func karmadaSearchAPIService(client *aggregator.Clientset, karmadaControlPlaneServiceName, karmadaControlPlaneNamespace, caBundle string) error {
func karmadaSearchAPIService(client aggregator.Interface, karmadaControlPlaneServiceName, karmadaControlPlaneNamespace, caBundle string) error {
apiServiceBytes, err := util.ParseTemplate(KarmadaSearchAPIService, struct {
ServiceName, Namespace string
CABundle string
Expand Down
4 changes: 2 additions & 2 deletions operator/pkg/util/apiclient/idempotency.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func NewCRDsClient(c *rest.Config) (*crdsclient.Clientset, error) {
}

// NewAPIRegistrationClient is to create an apiregistration ClientSet
func NewAPIRegistrationClient(c *rest.Config) (*aggregator.Clientset, error) {
func NewAPIRegistrationClient(c *rest.Config) (aggregator.Interface, error) {
return aggregator.NewForConfig(c)
}

Expand Down Expand Up @@ -183,7 +183,7 @@ func CreateOrUpdateValidatingWebhookConfiguration(client clientset.Interface, vw
}

// CreateOrUpdateAPIService creates a APIService if the target resource doesn't exist. If the resource exists already, this function will update the resource instead.
func CreateOrUpdateAPIService(apiRegistrationClient *aggregator.Clientset, apiservice *apiregistrationv1.APIService) error {
func CreateOrUpdateAPIService(apiRegistrationClient aggregator.Interface, apiservice *apiregistrationv1.APIService) error {
_, err := apiRegistrationClient.ApiregistrationV1().APIServices().Create(context.TODO(), apiservice, metav1.CreateOptions{})
if err != nil {
if !apierrors.IsAlreadyExists(err) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/karmadactl/addons/init/global.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ type GlobalCommandOptions struct {

KarmadaRestConfig *rest.Config

KarmadaAggregatorClientSet *aggregator.Clientset
KarmadaAggregatorClientSet aggregator.Interface
}

// AddFlags adds flags to the specified FlagSet.
Expand Down
2 changes: 1 addition & 1 deletion pkg/karmadactl/cmdinit/karmada/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
)

// WaitAPIServiceReady wait the api service condition true
func WaitAPIServiceReady(c *aggregator.Clientset, name string, timeout time.Duration) error {
func WaitAPIServiceReady(c aggregator.Interface, name string, timeout time.Duration) error {
if err := wait.PollUntilContextTimeout(context.TODO(), time.Second, timeout, true, func(ctx context.Context) (done bool, err error) {
apiService, e := c.ApiregistrationV1().APIServices().Get(ctx, name, metav1.GetOptions{})
if e != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/karmadactl/util/apiclient/apiclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func NewCRDsClient(c *rest.Config) (*clientset.Clientset, error) {
}

// NewAPIRegistrationClient is to create an apiregistration ClientSet
func NewAPIRegistrationClient(c *rest.Config) (*aggregator.Clientset, error) {
func NewAPIRegistrationClient(c *rest.Config) (aggregator.Interface, error) {
return aggregator.NewForConfig(c)
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/karmadactl/util/idempotency.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func CreateOrUpdateDeployment(client kubernetes.Interface, deploy *appsv1.Deploy

// CreateOrUpdateAPIService creates a ApiService if the target resource doesn't exist.
// If the resource exists already, this function will update the resource instead.
func CreateOrUpdateAPIService(apiRegistrationClient *aggregator.Clientset, apiservice *apiregistrationv1.APIService) error {
func CreateOrUpdateAPIService(apiRegistrationClient aggregator.Interface, apiservice *apiregistrationv1.APIService) error {
if _, err := apiRegistrationClient.ApiregistrationV1().APIServices().Create(context.TODO(), apiservice, metav1.CreateOptions{}); err != nil {
if !apierrors.IsAlreadyExists(err) {
return fmt.Errorf("unable to create APIService: %v", err)
Expand Down
2 changes: 1 addition & 1 deletion pkg/karmadactl/util/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func VerifyClustersExist(input []string, clusters *clusterv1alpha1.ClusterList)
}
}
if len(nonExistClusters) != 0 {
return fmt.Errorf("clusters don't exist: " + strings.Join(nonExistClusters, ","))
return fmt.Errorf("clusters don't exist: %s", strings.Join(nonExistClusters, ","))
}

return nil
Expand Down

0 comments on commit 6c490dc

Please sign in to comment.