Skip to content

Commit e16d1ea

Browse files
committed
try to get metadata out
1 parent 72fb230 commit e16d1ea

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ build: $(CMD)
3636
.PHONY: $(CMD)
3737
$(CMD): %: $(BUILD_DEST)/%
3838

39-
$(BUILD_DEST)/%: cmd/%
39+
$(BUILD_DEST)/%: clean cmd/%
4040
go build $(GOTOOLFLAGS) -o $@ ./cmd/$*
4141

4242
GOLANGCI_LINT = _tools/golangci-lint

internal/sync/syncer_related.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ import (
2525
"go.uber.org/zap"
2626

2727
"github.com/kcp-dev/api-syncagent/internal/mutation"
28+
"github.com/kcp-dev/api-syncagent/internal/projection"
2829
syncagentv1alpha1 "github.com/kcp-dev/api-syncagent/sdk/apis/syncagent/v1alpha1"
30+
"github.com/kcp-dev/logicalcluster/v3"
2931

3032
apierrors "k8s.io/apimachinery/pkg/api/errors"
3133
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
@@ -85,12 +87,22 @@ func (s *ResourceSyncer) processRelatedResource(log *zap.SugaredLogger, stateSto
8587
sourceObjs.SetKind(relRes.Kind)
8688

8789
// TODO: would need to handle replacer here as well to select right object.
90+
cn, ok := source.object.GetLabels()[remoteObjectClusterLabel]
91+
if !ok {
92+
return false, fmt.Errorf("missing cluster label on source object")
93+
}
94+
clusterName := logicalcluster.Name(cn)
95+
labels := projection.GenerateLocalLabelSelector(&relRes, source.object, clusterName)
8896

89-
if err := source.client.List(source.ctx, sourceObjs, ctrlruntimeclient.MatchingLabels(relRes.LabelSelector.MatchLabels)); err != nil {
97+
if err := source.client.List(source.ctx, sourceObjs, ctrlruntimeclient.MatchingLabels(labels.MatchLabels)); err != nil {
9098
return false, fmt.Errorf("failed to list related objects: %w", err)
9199
}
92-
if len(sourceObjs.Items) == 0 || len(sourceObjs.Items) > 1 {
93-
return false, fmt.Errorf("expected exactly one related object, got %d", len(sourceObjs.Items))
100+
if len(sourceObjs.Items) == 0 {
101+
return false, nil
102+
}
103+
if len(sourceObjs.Items) > 1 {
104+
// HACK: we take first one, as we can't select multiple objects or by name only!
105+
log.Warnw("found multiple related objects, taking first one", "count", len(sourceObjs.Items))
94106
}
95107
sourceKey = &ctrlruntimeclient.ObjectKey{
96108
Namespace: sourceObjs.Items[0].GetNamespace(),

0 commit comments

Comments
 (0)