Skip to content
This repository was archived by the owner on May 9, 2025. It is now read-only.

Commit 9604f7b

Browse files
authored
Merge pull request #6 from open-component-model/update-controller
chore(update): updating the git-sync controller to work with latest ocm-controller
2 parents 3e12bcc + d041438 commit 9604f7b

File tree

15 files changed

+1169
-473
lines changed

15 files changed

+1169
-473
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Build the manager binary
2-
FROM golang:1.19 as builder
2+
FROM golang:1.20 as builder
33
ARG TARGETOS
44
ARG TARGETARCH
55

api/v1alpha1/gitsync_types.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
package v1alpha1
77

88
import (
9-
"time"
10-
119
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1210
)
1311

@@ -28,7 +26,7 @@ type CommitTemplate struct {
2826
type GitSyncSpec struct {
2927
ComponentRef Ref `json:"componentRef"`
3028
SnapshotRef Ref `json:"snapshotRef"`
31-
Interval time.Duration `json:"interval"`
29+
Interval metav1.Duration `json:"interval"`
3230
URL string `json:"url"`
3331
Branch string `json:"branch"`
3432
AuthRef Ref `json:"authRef"`

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/delivery.ocm.software_gitsyncs.yaml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,7 @@ spec:
7575
- namespace
7676
type: object
7777
interval:
78-
description: A Duration represents the elapsed time between two instants
79-
as an int64 nanosecond count. The representation limits the largest
80-
representable duration to approximately 290 years.
81-
format: int64
82-
type: integer
78+
type: string
8379
prune:
8480
type: boolean
8581
snapshotRef:

config/manager/deployment.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ spec:
3131
- /manager
3232
args:
3333
- --leader-elect
34+
- --oci-registry-addr=registry.ocm-system.svc.cluster.local:5000
3435
image: open-component-model/git-sync-controller:latest
3536
name: manager
3637
securityContext:

config/rbac/role.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ rules:
1212
verbs:
1313
- get
1414
- list
15+
- watch
1516
- apiGroups:
1617
- delivery.ocm.software
1718
resources:
Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,23 @@
11
apiVersion: delivery.ocm.software/v1alpha1
22
kind: GitSync
33
metadata:
4-
labels:
5-
app.kubernetes.io/name: gitsync
6-
app.kubernetes.io/instance: gitsync-sample
7-
app.kubernetes.io/part-of: git-sync-controller
8-
app.kuberentes.io/managed-by: kustomize
9-
app.kubernetes.io/created-by: git-sync-controller
10-
name: gitsync-sample
4+
name: git-sync-sample
5+
namespace: ocm-system
116
spec:
12-
# TODO(user): Add fields here
7+
authRef:
8+
name: git-sync-secret
9+
namespace: ocm-system
10+
branch: main
11+
commitTemplate:
12+
email: <email>
13+
message: "Update made from git-sync-controller"
14+
name: Gergely Brautigam
15+
interval: 10m0s
16+
subPath: ./application/podinfo
17+
url: https://github.com/Skarlso/test
18+
componentRef:
19+
name: ocm-test-component
20+
namespace: ocm-system
21+
snapshotRef:
22+
name: ocm-test-snapshot
23+
namespace: ocm-system

controllers/gitsync_controller.go

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ import (
1010
"fmt"
1111
"time"
1212

13+
"github.com/fluxcd/pkg/runtime/patch"
1314
corev1 "k8s.io/api/core/v1"
1415
apierrors "k8s.io/apimachinery/pkg/api/errors"
1516
"k8s.io/apimachinery/pkg/runtime"
1617
"k8s.io/apimachinery/pkg/types"
17-
"sigs.k8s.io/cluster-api/util/patch"
1818
ctrl "sigs.k8s.io/controller-runtime"
1919
"sigs.k8s.io/controller-runtime/pkg/client"
2020
"sigs.k8s.io/controller-runtime/pkg/log"
@@ -37,7 +37,7 @@ type GitSyncReconciler struct {
3737
//+kubebuilder:rbac:groups=delivery.ocm.software,resources=gitsyncs/status,verbs=get;update;patch
3838
//+kubebuilder:rbac:groups=delivery.ocm.software,resources=gitsyncs/finalizers,verbs=update
3939
//+kubebuilder:rbac:groups=delivery.ocm.software,resources=ocmresources,verbs=get;list;watch;create;update;patch;delete
40-
//+kubebuilder:rbac:groups="",resources=secrets,verbs=get;list
40+
//+kubebuilder:rbac:groups="",resources=secrets,verbs=get;list;watch
4141
//+kubebuilder:rbac:groups=delivery.ocm.software,resources=snapshots,verbs=get;list;watch;create;update;patch;delete
4242
//+kubebuilder:rbac:groups=delivery.ocm.software,resources=snapshots/status,verbs=get;update;patch
4343

@@ -65,32 +65,32 @@ func (r *GitSyncReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
6565
Namespace: gitSync.Spec.SnapshotRef.Namespace,
6666
Name: gitSync.Spec.SnapshotRef.Name,
6767
}, snapshot); err != nil {
68-
return requeue(gitSync.Spec.Interval), fmt.Errorf("failed to find snapshot: %w", err)
68+
return ctrl.Result{}, fmt.Errorf("failed to find snapshot: %w", err)
6969
}
7070
authSecret := &corev1.Secret{}
7171
if err := r.Get(ctx, types.NamespacedName{
7272
Namespace: gitSync.Spec.AuthRef.Namespace,
7373
Name: gitSync.Spec.AuthRef.Name,
7474
}, authSecret); err != nil {
75-
return requeue(gitSync.Spec.Interval), fmt.Errorf("failed to find authentication secret: %w", err)
75+
return ctrl.Result{}, fmt.Errorf("failed to find authentication secret: %w", err)
7676
}
7777

7878
// trim any trailing `/` and then just add.
79-
log.V(4).Info("crafting artifact URL to download from", "url", snapshot.Status.Image)
79+
log.V(4).Info("crafting artifact URL to download from", "url", snapshot.Status.RepositoryURL)
8080
opts := &providers.PushOptions{
81-
URL: gitSync.Spec.URL,
82-
Message: gitSync.Spec.CommitTemplate.Message,
83-
Name: gitSync.Spec.CommitTemplate.Name,
84-
Email: gitSync.Spec.CommitTemplate.Email,
85-
SnapshotURL: snapshot.Status.Image,
86-
Branch: gitSync.Spec.Branch,
87-
SubPath: gitSync.Spec.SubPath,
81+
URL: gitSync.Spec.URL,
82+
Message: gitSync.Spec.CommitTemplate.Message,
83+
Name: gitSync.Spec.CommitTemplate.Name,
84+
Email: gitSync.Spec.CommitTemplate.Email,
85+
Snapshot: snapshot,
86+
Branch: gitSync.Spec.Branch,
87+
SubPath: gitSync.Spec.SubPath,
8888
}
8989
r.parseAuthSecret(authSecret, opts)
9090

9191
digest, err := r.Git.Push(ctx, opts)
9292
if err != nil {
93-
return requeue(gitSync.Spec.Interval), fmt.Errorf("failed to push to git repository: %w", err)
93+
return ctrl.Result{}, fmt.Errorf("failed to push to git repository: %w", err)
9494
}
9595
// Initialize the patch helper.
9696
patchHelper, err := patch.NewHelper(gitSync, r.Client)
@@ -111,12 +111,6 @@ func (r *GitSyncReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
111111
return ctrl.Result{}, nil
112112
}
113113

114-
func requeue(seconds time.Duration) ctrl.Result {
115-
return ctrl.Result{
116-
RequeueAfter: seconds * time.Second,
117-
}
118-
}
119-
120114
// SetupWithManager sets up the controller with the Manager.
121115
func (r *GitSyncReconciler) SetupWithManager(mgr ctrl.Manager) error {
122116
return ctrl.NewControllerManagedBy(mgr).

0 commit comments

Comments
 (0)