Skip to content
This repository was archived by the owner on May 9, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions apis/delivery/v1alpha1/sync_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package v1alpha1
import (
"time"

"github.com/fluxcd/pkg/apis/meta"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
Expand All @@ -33,12 +34,12 @@ type PullRequestTemplate struct {

// SyncSpec defines the desired state of Sync
type SyncSpec struct {
SnapshotRef v1.LocalObjectReference `json:"snapshotRef"`
RepositoryRef v1.LocalObjectReference `json:"repositoryRef"`
Interval metav1.Duration `json:"interval"`
CommitTemplate CommitTemplate `json:"commitTemplate"`
SubPath string `json:"subPath"`
Prune bool `json:"prune,omitempty"`
SnapshotRef v1.LocalObjectReference `json:"snapshotRef"`
RepositoryRef meta.NamespacedObjectReference `json:"repositoryRef"`
Interval metav1.Duration `json:"interval"`
CommitTemplate CommitTemplate `json:"commitTemplate"`
SubPath string `json:"subPath"`
Prune bool `json:"prune,omitempty"`

//+optional
AutomaticPullRequestCreation bool `json:"automaticPullRequestCreation,omitempty"`
Expand Down
14 changes: 9 additions & 5 deletions config/crd/bases/delivery.ocm.software_syncs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,19 @@ spec:
type: string
type: object
repositoryRef:
description: LocalObjectReference contains enough information to let
you locate the referenced object inside the same namespace.
description: NamespacedObjectReference contains enough information
to locate the referenced Kubernetes resource object in any namespace.
properties:
name:
description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
TODO: Add other useful fields. apiVersion, kind, uid?'
description: Name of the referent.
type: string
namespace:
description: Namespace of the referent, when not specified it
acts as LocalObjectReference.
type: string
required:
- name
type: object
x-kubernetes-map-type: atomic
snapshotRef:
description: LocalObjectReference contains enough information to let
you locate the referenced object inside the same namespace.
Expand Down
9 changes: 7 additions & 2 deletions controllers/delivery/sync_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,14 @@ func (r *SyncReconciler) Reconcile(ctx context.Context, req ctrl.Request) (resul

log.V(4).Info("found target snapshot")

namespace := obj.Spec.RepositoryRef.Namespace
if namespace == "" {
namespace = obj.Namespace
}

repository := &mpasv1alpha1.Repository{}
if err = r.Get(ctx, types.NamespacedName{
Namespace: obj.Namespace,
Namespace: namespace,
Name: obj.Spec.RepositoryRef.Name,
}, repository); err != nil {
err = fmt.Errorf("failed to find repository: %w", err)
Expand All @@ -156,7 +161,7 @@ func (r *SyncReconciler) Reconcile(ctx context.Context, req ctrl.Request) (resul

authSecret := &corev1.Secret{}
if err = r.Get(ctx, types.NamespacedName{
Namespace: obj.Namespace,
Namespace: repository.Namespace,
Name: repository.Spec.Credentials.SecretRef.Name,
}, authSecret); err != nil {
err = fmt.Errorf("failed to find authentication secret: %w", err)
Expand Down
6 changes: 3 additions & 3 deletions controllers/delivery/sync_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func TestSyncReconciler(t *testing.T) {
SnapshotRef: v1.LocalObjectReference{
Name: snapshot.Name,
},
RepositoryRef: v1.LocalObjectReference{
RepositoryRef: meta.NamespacedObjectReference{
Name: repository.Name,
},
CommitTemplate: v1alpha1.CommitTemplate{
Expand Down Expand Up @@ -117,7 +117,7 @@ func TestSyncReconcilerIsSkippedIfDigestIsAlreadyPresent(t *testing.T) {
SnapshotRef: v1.LocalObjectReference{
Name: "test",
},
RepositoryRef: v1.LocalObjectReference{
RepositoryRef: meta.NamespacedObjectReference{
Name: "test",
},
CommitTemplate: v1alpha1.CommitTemplate{
Expand Down Expand Up @@ -198,7 +198,7 @@ func TestSyncReconcilerWithAutomaticPullRequest(t *testing.T) {
SnapshotRef: v1.LocalObjectReference{
Name: snapshot.Name,
},
RepositoryRef: v1.LocalObjectReference{
RepositoryRef: meta.NamespacedObjectReference{
Name: repository.Name,
},
CommitTemplate: v1alpha1.CommitTemplate{
Expand Down