Skip to content
This repository was archived by the owner on Apr 24, 2024. It is now read-only.

Commit 754a2c1

Browse files
committed
Default APIExport name to avoid watching for multiple APIExports
1 parent 5892587 commit 754a2c1

File tree

1 file changed

+5
-16
lines changed

1 file changed

+5
-16
lines changed

main.go

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"flag"
2222
"fmt"
2323
"os"
24-
"strings"
2524

2625
"k8s.io/apimachinery/pkg/fields"
2726
"k8s.io/apimachinery/pkg/runtime"
@@ -69,7 +68,7 @@ func main() {
6968
var enableLeaderElection bool
7069
var probeAddr string
7170
var apiExportName string
72-
flag.StringVar(&apiExportName, "api-export-name", "", "The name of the APIExport.")
71+
flag.StringVar(&apiExportName, "api-export-name", "data.my.domain", "The name of the APIExport.")
7372
flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.")
7473
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
7574
flag.BoolVar(&enableLeaderElection, "leader-elect", false,
@@ -176,14 +175,10 @@ func restConfigForAPIExport(ctx context.Context, cfg *rest.Config, apiExportName
176175
return nil, fmt.Errorf("error creating APIExport client: %w", err)
177176
}
178177

179-
var opts []client.ListOption
180-
if apiExportName != "" {
181-
opts = append(opts, client.MatchingFieldsSelector{
182-
Selector: fields.OneTermEqualSelector("metadata.name", apiExportName),
183-
})
178+
selector := client.MatchingFieldsSelector{
179+
Selector: fields.OneTermEqualSelector("metadata.name", apiExportName),
184180
}
185-
186-
watch, err := apiExportClient.Watch(ctx, &apisv1alpha1.APIExportList{}, opts...)
181+
watch, err := apiExportClient.Watch(ctx, &apisv1alpha1.APIExportList{}, selector)
187182
if err != nil {
188183
return nil, fmt.Errorf("error watching for APIExport: %w", err)
189184
}
@@ -197,7 +192,7 @@ func restConfigForAPIExport(ctx context.Context, cfg *rest.Config, apiExportName
197192
if !ok {
198193
// The channel has been closed. Let's retry watching in case it timed out on idle,
199194
// or fail in case connection to the server cannot be re-established.
200-
watch, err = apiExportClient.Watch(ctx, &apisv1alpha1.APIExportList{}, opts...)
195+
watch, err = apiExportClient.Watch(ctx, &apisv1alpha1.APIExportList{}, selector)
201196
if err != nil {
202197
return nil, fmt.Errorf("error watching for APIExport: %w", err)
203198
}
@@ -210,12 +205,6 @@ func restConfigForAPIExport(ctx context.Context, cfg *rest.Config, apiExportName
210205

211206
setupLog.Info("APIExport event received", "name", apiExport.Name, "event", e.Type)
212207

213-
if resources := apiExport.Spec.LatestResourceSchemas; apiExportName == "" &&
214-
(len(resources) == 0 || !strings.HasSuffix(resources[0], datav1alpha1.GroupVersion.Group)) {
215-
// This is not this controller APIExport
216-
continue
217-
}
218-
219208
if !conditions.IsTrue(apiExport, apisv1alpha1.APIExportVirtualWorkspaceURLsReady) {
220209
setupLog.Info("APIExport virtual workspace URLs are not ready", "APIExport", apiExport.Name)
221210
continue

0 commit comments

Comments
 (0)