@@ -13,17 +13,14 @@ import (
1313 "github.com/fluxcd/pkg/apis/meta"
1414 "github.com/fluxcd/pkg/runtime/conditions"
1515 "github.com/fluxcd/pkg/runtime/patch"
16- sourcebeta2 "github.com/fluxcd/source-controller/api/v1beta2"
1716 corev1 "k8s.io/api/core/v1"
1817 apierrors "k8s.io/apimachinery/pkg/api/errors"
1918 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2019 "k8s.io/apimachinery/pkg/runtime"
2120 "k8s.io/apimachinery/pkg/types"
22- "k8s.io/utils/pointer"
2321 ctrl "sigs.k8s.io/controller-runtime"
2422 "sigs.k8s.io/controller-runtime/pkg/builder"
2523 "sigs.k8s.io/controller-runtime/pkg/client"
26- "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
2724 "sigs.k8s.io/controller-runtime/pkg/log"
2825 "sigs.k8s.io/controller-runtime/pkg/predicate"
2926
@@ -223,20 +220,15 @@ func (r *SyncReconciler) Reconcile(ctx context.Context, req ctrl.Request) (resul
223220 if obj .Spec .AutomaticPullRequestCreation {
224221 log .Info ("automatic pull-request creation is enabled, preparing to create a pull request" )
225222
226- if err = r .Provider .CreatePullRequest (ctx , targetBranch , * obj , * repository ); err != nil {
223+ id , err := r .Provider .CreatePullRequest (ctx , targetBranch , * obj , * repository )
224+ if err != nil {
227225 err = fmt .Errorf ("failed to create pull request: %w" , err )
228226 conditions .MarkFalse (obj , meta .ReadyCondition , v1alpha1 .CreatePullRequestFailedReason , err .Error ())
229227
230228 return ctrl.Result {}, err
231229 }
232230
233- // Create GitRepository to track values file changes.
234- if err := r .createValueFileGitRepository (ctx , * obj , * repository , targetBranch ); err != nil {
235- err = fmt .Errorf ("failed to create value tracking git repository object: %w" , err )
236- conditions .MarkFalse (obj , meta .ReadyCondition , v1alpha1 .GitRepositoryCreateFailedReason , err .Error ())
237-
238- return ctrl.Result {}, err
239- }
231+ obj .Status .PullRequestID = id
240232 }
241233
242234 // Remove any stale Ready condition, most likely False, set above. Its value
@@ -275,47 +267,3 @@ func (r *SyncReconciler) parseAuthSecret(secret *corev1.Secret, opts *pkg.PushOp
275267 },
276268 }
277269}
278-
279- // createValueFileGitRepository creates a GitRepository that tracks changes on a branch.
280- func (r * SyncReconciler ) createValueFileGitRepository (ctx context.Context , sync v1alpha1.Sync , repository mpasv1alpha1.Repository , branch string ) error {
281- owners := sync .GetOwnerReferences ()
282- if len (owners ) != 1 {
283- return fmt .Errorf ("expected exactly one owner, got: %d" , len (owners ))
284- }
285-
286- repo := & sourcebeta2.GitRepository {
287- ObjectMeta : metav1.ObjectMeta {
288- Name : repository .Name + "values-repo" ,
289- Namespace : repository .Namespace ,
290- },
291- Spec : sourcebeta2.GitRepositorySpec {
292- URL : repository .GetRepositoryURL (),
293- SecretRef : & meta.LocalObjectReference {
294- Name : repository .Spec .Credentials .SecretRef .Name ,
295- },
296- Interval : metav1.Duration {Duration : 5 * time .Second },
297- Reference : & sourcebeta2.GitRepositoryRef {
298- Branch : branch ,
299- },
300- Ignore : pointer .String (fmt .Sprintf (`# exclude all
301- /*
302- # include values.yaml
303- !./products/%s/values.yaml
304- ` , owners [0 ].Name )),
305- },
306- }
307-
308- if _ , err := controllerutil .CreateOrUpdate (ctx , r .Client , repo , func () error {
309- if repo .ObjectMeta .CreationTimestamp .IsZero () {
310- if err := controllerutil .SetOwnerReference (& repository , repo , r .Scheme ); err != nil {
311- return fmt .Errorf ("failed to set owner to git repository object: %w" , err )
312- }
313- }
314-
315- return nil
316- }); err != nil {
317- return fmt .Errorf ("failed to create git repository: %w" , err )
318- }
319-
320- return nil
321- }
0 commit comments