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
3 changes: 3 additions & 0 deletions apis/delivery/v1alpha1/condition_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ const (
// SnapshotGetFailedReason is used when the needed snapshot does not exist.
SnapshotGetFailedReason = "SnapshotGetFailed"

// RepositoryGetFailedReason is used when the needed repository does not exist.
RepositoryGetFailedReason = "RepositoryGetFailed"

// CredentialsNotFoundReason is used when the needed authentication does not exist.
CredentialsNotFoundReason = "CredentialsNotFound"

Expand Down
26 changes: 12 additions & 14 deletions apis/delivery/v1alpha1/sync_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,10 @@ package v1alpha1
import (
"time"

v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// Ref defines a name and namespace ref to any object.
type Ref struct {
Name string `json:"name"`
Namespace string `json:"namespace"`
}

// CommitTemplate defines the details of the commit to the external repository.
type CommitTemplate struct {
Name string `json:"name"`
Expand All @@ -25,14 +20,17 @@ type CommitTemplate struct {

// SyncSpec defines the desired state of Sync
type SyncSpec struct {
SnapshotRef Ref `json:"snapshotRef"`
Interval metav1.Duration `json:"interval"`
URL string `json:"url"`
Branch string `json:"branch"`
AuthRef Ref `json:"authRef"`
CommitTemplate *CommitTemplate `json:"commitTemplate"`
SubPath string `json:"subPath"`
Prune bool `json:"prune,omitempty"`
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"`

//+optional
Branch string `json:"branch,omitempty"`
//+optional
AutomaticPullRequestCreation bool `json:"automaticPullRequestCreation,omitempty"`
}

// SyncStatus defines the observed state of Sync
Expand Down
17 changes: 1 addition & 16 deletions apis/delivery/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 28 additions & 9 deletions apis/mpas/v1alpha1/repository_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,17 @@
package v1alpha1

import (
"fmt"
"strings"
"time"

v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// SecretRef is a reference to a secret in the same namespace as the referencing object.
type SecretRef struct {
Name string `json:"name"`
}

// Credentials contains ways of authenticating the creation of a repository.
type Credentials struct {
SecretRef SecretRef `json:"secretRef"`
SecretRef v1.LocalObjectReference `json:"secretRef"`
}

// ExistingRepositoryPolicy defines what to do in case a requested repository already exists.
Expand Down Expand Up @@ -53,9 +51,6 @@ type RepositorySpec struct {
//+optional
Maintainers []string `json:"maintainers,omitempty"`
//+optional
//+kubebuilder:default:=true
AutomaticPullRequestCreation bool `json:"automaticPullRequestCreation,omitempty"`
//+optional
//+kubebuilder:default:=adopt
//+kubebuilder:validation:Enum=adopt;fail
ExistingRepositoryPolicy ExistingRepositoryPolicy `json:"existingRepositoryPolicy,omitempty"`
Expand Down Expand Up @@ -89,6 +84,30 @@ func (in Repository) GetRequeueAfter() time.Duration {
return in.Spec.Interval.Duration
}

// GetRepositoryURL construct a repository URL based on either domain or the provider data.
func (in Repository) GetRepositoryURL() string {
if in.Spec.Domain != "" {
if strings.Contains(in.Spec.Domain, "@") {
return fmt.Sprintf("%s:%s/%s", in.Spec.Domain, in.Spec.Owner, in.Spec.RepositoryName)
}

return fmt.Sprintf("%s/%s/%s", in.Spec.Domain, in.Spec.Owner, in.Spec.RepositoryName)
}

domain := ""

switch in.Spec.Provider {
case "github":
domain = "github.com"
case "gitlab":
domain = "gitlab.com"
case "gitea":
domain = "gitea.com"
}

return fmt.Sprintf("https://%s/%s/%s", domain, in.Spec.Owner, in.Spec.RepositoryName)
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status

Expand Down
15 changes: 0 additions & 15 deletions apis/mpas/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 18 additions & 22 deletions config/crd/bases/delivery.ocm.software_syncs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,8 @@ spec:
spec:
description: SyncSpec defines the desired state of Sync
properties:
authRef:
description: Ref defines a name and namespace ref to any object.
properties:
name:
type: string
namespace:
type: string
required:
- name
- namespace
type: object
automaticPullRequestCreation:
type: boolean
branch:
type: string
commitTemplate:
Expand All @@ -67,29 +58,34 @@ spec:
type: string
prune:
type: boolean
snapshotRef:
description: Ref defines a name and namespace ref to any object.
repositoryRef:
description: LocalObjectReference contains enough information to let
you locate the referenced object inside the same 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?'
type: string
namespace:
type: object
x-kubernetes-map-type: atomic
snapshotRef:
description: LocalObjectReference contains enough information to let
you locate the referenced object inside the same 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?'
type: string
required:
- name
- namespace
type: object
x-kubernetes-map-type: atomic
subPath:
type: string
url:
type: string
required:
- authRef
- branch
- commitTemplate
- interval
- repositoryRef
- snapshotRef
- subPath
- url
type: object
status:
description: SyncStatus defines the observed state of Sync
Expand Down
12 changes: 5 additions & 7 deletions config/crd/bases/mpas.ocm.software_repositories.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,20 @@ spec:
spec:
description: RepositorySpec defines the desired state of Repository
properties:
automaticPullRequestCreation:
default: true
type: boolean
credentials:
description: Credentials contains ways of authenticating the creation
of a repository.
properties:
secretRef:
description: SecretRef is a reference to a secret in the same
namespace as the referencing object.
description: LocalObjectReference contains enough information
to let you locate the referenced object inside the same 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?'
type: string
required:
- name
type: object
x-kubernetes-map-type: atomic
required:
- secretRef
type: object
Expand Down
10 changes: 2 additions & 8 deletions config/samples/delivery_v1alpha1_sync.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,14 @@ metadata:
name: git-sample
namespace: ocm-system
spec:
authRef:
name: git-secret
namespace: ocm-system
branch: main
commitTemplate:
email: <email>
message: "Update made from git-controller"
name: Gergely Brautigam
interval: 10m0s
subPath: ./application/podinfo
url: https://github.com/Skarlso/test
componentRef:
name: ocm-test-component
namespace: ocm-system
snapshotRef:
name: ocm-test-snapshot
namespace: ocm-system
repositoryRef:
name: test-repositroy
20 changes: 16 additions & 4 deletions controllers/delivery/sync_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
ocmv1 "github.com/open-component-model/ocm-controller/api/v1alpha1"

"github.com/open-component-model/git-controller/apis/delivery/v1alpha1"
mpasv1alpha1 "github.com/open-component-model/git-controller/apis/mpas/v1alpha1"
providers "github.com/open-component-model/git-controller/pkg"
)

Expand Down Expand Up @@ -129,7 +130,7 @@ func (r *SyncReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.

snapshot := &ocmv1.Snapshot{}
if err := r.Get(ctx, types.NamespacedName{
Namespace: obj.Spec.SnapshotRef.Namespace,
Namespace: obj.Namespace,
Name: obj.Spec.SnapshotRef.Name,
}, snapshot); err != nil {
retErr = fmt.Errorf("failed to find snapshot: %w", err)
Expand All @@ -138,10 +139,21 @@ func (r *SyncReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.
return ctrl.Result{}, retErr
}

repository := &mpasv1alpha1.Repository{}
if err := r.Get(ctx, types.NamespacedName{
Namespace: obj.Namespace,
Name: obj.Spec.RepositoryRef.Name,
}, repository); err != nil {
retErr = fmt.Errorf("failed to find repository: %w", err)
conditions.MarkFalse(obj, meta.ReadyCondition, v1alpha1.RepositoryGetFailedReason, retErr.Error())

return ctrl.Result{}, retErr
}

authSecret := &corev1.Secret{}
if err := r.Get(ctx, types.NamespacedName{
Namespace: obj.Spec.AuthRef.Namespace,
Name: obj.Spec.AuthRef.Name,
Namespace: obj.Namespace,
Name: repository.Spec.Credentials.SecretRef.Name,
}, authSecret); err != nil {
retErr = fmt.Errorf("failed to find authentication secret: %w", err)
conditions.MarkFalse(obj, meta.ReadyCondition, v1alpha1.CredentialsNotFoundReason, retErr.Error())
Expand All @@ -152,7 +164,7 @@ func (r *SyncReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.
// trim any trailing `/` and then just add.
log.V(4).Info("crafting artifact URL to download from", "url", snapshot.Status.RepositoryURL)
opts := &providers.PushOptions{
URL: obj.Spec.URL,
URL: repository.GetRepositoryURL(),
Message: obj.Spec.CommitTemplate.Message,
Name: obj.Spec.CommitTemplate.Name,
Email: obj.Spec.CommitTemplate.Email,
Expand Down
Loading