Skip to content

Commit

Permalink
Merge pull request #4210 from wawa0210/master
Browse files Browse the repository at this point in the history
fix karmada instance aggregated service externalName error
  • Loading branch information
karmada-bot authored Nov 9, 2023
2 parents 996d1a2 + 9ec3c40 commit fd03daa
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 26 deletions.
52 changes: 30 additions & 22 deletions operator/pkg/karmadaresource/apiservice/apiservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,22 @@ func init() {
}

// EnsureAggregatedAPIService creates aggregated APIService and a service
func EnsureAggregatedAPIService(aggregatorClient *aggregator.Clientset, client clientset.Interface, name, namespace, caBundle string) error {
if err := aggregatedApiserverService(client, name, namespace); err != nil {
func EnsureAggregatedAPIService(aggregatorClient *aggregator.Clientset, 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, name, namespace, caBundle)
return aggregatedAPIService(aggregatorClient, karmadaControlPlaneServiceName, karmadaControlPlaneNamespace, caBundle)
}

func aggregatedAPIService(client *aggregator.Clientset, name, namespace, caBundle string) error {
func aggregatedAPIService(client *aggregator.Clientset, karmadaControlPlaneServiceName, karmadaControlPlaneNamespace, caBundle string) error {
apiServiceBytes, err := util.ParseTemplate(KarmadaAggregatedAPIService, struct {
Namespace string
ServiceName string
CABundle string
}{
Namespace: namespace,
ServiceName: util.KarmadaAggregatedAPIServerName(name),
Namespace: karmadaControlPlaneNamespace,
ServiceName: util.KarmadaAggregatedAPIServerName(karmadaControlPlaneServiceName),
CABundle: caBundle,
})
if err != nil {
Expand All @@ -60,13 +60,17 @@ func aggregatedAPIService(client *aggregator.Clientset, name, namespace, caBundl
return apiclient.CreateOrUpdateAPIService(client, apiService)
}

func aggregatedApiserverService(client clientset.Interface, name, namespace string) error {
func aggregatedApiserverService(client clientset.Interface, karmadaControlPlaneServiceName, karmadaControlPlaneNamespace, hostClusterServiceName, hostClusterNamespace string) error {
aggregatedApiserverServiceBytes, err := util.ParseTemplate(KarmadaAggregatedApiserverService, struct {
Namespace string
ServiceName string
Namespace string
ServiceName string
HostClusterServiceName string
HostClusterNamespace string
}{
Namespace: namespace,
ServiceName: util.KarmadaAggregatedAPIServerName(name),
Namespace: karmadaControlPlaneNamespace,
ServiceName: util.KarmadaAggregatedAPIServerName(karmadaControlPlaneServiceName),
HostClusterServiceName: util.KarmadaAggregatedAPIServerName(hostClusterServiceName),
HostClusterNamespace: hostClusterNamespace,
})
if err != nil {
return fmt.Errorf("error when parsing AggregatedApiserver Service template: %w", err)
Expand All @@ -81,15 +85,15 @@ func aggregatedApiserverService(client clientset.Interface, name, namespace stri
}

// EnsureMetricsAdapterAPIService creates APIService and a service for karmada-metrics-adapter
func EnsureMetricsAdapterAPIService(aggregatorClient *aggregator.Clientset, client clientset.Interface, name, namespace, caBundle string) error {
if err := karmadaMetricsAdapterService(client, name, namespace); err != nil {
func EnsureMetricsAdapterAPIService(aggregatorClient *aggregator.Clientset, 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, name, namespace, caBundle)
return karmadaMetricsAdapterAPIService(aggregatorClient, karmadaControlPlaneServiceName, karmadaControlPlaneNamespace, caBundle)
}

func karmadaMetricsAdapterAPIService(client *aggregator.Clientset, name, namespace, caBundle string) error {
func karmadaMetricsAdapterAPIService(client *aggregator.Clientset, 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 All @@ -100,10 +104,10 @@ func karmadaMetricsAdapterAPIService(client *aggregator.Clientset, name, namespa
CABundle string
}{
Name: apiServiceName,
Namespace: namespace,
Namespace: karmadaControlPlaneNamespace,
Group: gv.Group,
Version: gv.Version,
ServiceName: util.KarmadaMetricsAdapterName(name),
ServiceName: util.KarmadaMetricsAdapterName(karmadaControlPlaneServiceName),
CABundle: caBundle,
})
if err != nil {
Expand All @@ -123,13 +127,17 @@ func karmadaMetricsAdapterAPIService(client *aggregator.Clientset, name, namespa
return nil
}

func karmadaMetricsAdapterService(client clientset.Interface, name, namespace string) error {
func karmadaMetricsAdapterService(client clientset.Interface, karmadaControlPlaneServiceName, karmadaControlPlaneNamespace, hostClusterServiceName, hostClusterNamespace string) error {
aggregatedApiserverServiceBytes, err := util.ParseTemplate(KarmadaMetricsAdapterService, struct {
Namespace string
ServiceName string
Namespace string
ServiceName string
HostClusterServiceName string
HostClusterNamespace string
}{
Namespace: namespace,
ServiceName: util.KarmadaMetricsAdapterName(name),
Namespace: karmadaControlPlaneNamespace,
ServiceName: util.KarmadaMetricsAdapterName(karmadaControlPlaneServiceName),
HostClusterServiceName: util.KarmadaMetricsAdapterName(hostClusterServiceName),
HostClusterNamespace: hostClusterNamespace,
})
if err != nil {
return fmt.Errorf("error when parsing KarmadaMetricsAdapter Service template: %w", err)
Expand Down
4 changes: 2 additions & 2 deletions operator/pkg/karmadaresource/apiservice/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ metadata:
namespace: {{ .Namespace }}
spec:
type: ExternalName
externalName: {{ .ServiceName }}.{{ .Namespace }}.svc
externalName: {{ .HostClusterServiceName }}.{{ .HostClusterNamespace }}.svc
`

// KarmadaMetricsAdapterAPIService is karmada-metrics-adapter APIService manifest
Expand Down Expand Up @@ -59,6 +59,6 @@ metadata:
namespace: {{ .Namespace }}
spec:
type: ExternalName
externalName: {{ .ServiceName }}.{{ .Namespace }}.svc
externalName: {{ .HostClusterServiceName }}.{{ .HostClusterNamespace }}.svc
`
)
2 changes: 1 addition & 1 deletion operator/pkg/tasks/init/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ func runDeployMetricAdapterAPIService(r workflow.RunData) error {
}
caBase64 := base64.StdEncoding.EncodeToString(cert.CertData())

err = apiservice.EnsureMetricsAdapterAPIService(client, data.KarmadaClient(), data.GetName(), data.GetNamespace(), caBase64)
err = apiservice.EnsureMetricsAdapterAPIService(client, data.KarmadaClient(), data.GetName(), constants.KarmadaSystemNamespace, data.GetName(), data.GetNamespace(), caBase64)
if err != nil {
return fmt.Errorf("failed to apply karmada-metrics-adapter APIService resource to karmada controlplane, err: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion operator/pkg/tasks/init/karmadaresource.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ func runAPIService(r workflow.RunData) error {
}
caBase64 := base64.StdEncoding.EncodeToString(cert.CertData())

err = apiservice.EnsureAggregatedAPIService(client, data.KarmadaClient(), data.GetName(), data.GetNamespace(), caBase64)
err = apiservice.EnsureAggregatedAPIService(client, data.KarmadaClient(), data.GetName(), constants.KarmadaSystemNamespace, data.GetName(), data.GetNamespace(), caBase64)
if err != nil {
return fmt.Errorf("failed to apply aggregated APIService resource to karmada controlplane, err: %w", err)
}
Expand Down

0 comments on commit fd03daa

Please sign in to comment.