Created
October 25, 2024 03:00
-
-
Save inspirit941/d8cfdf5ccb2fcf5c416409d2be33eeb9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func (r *Reconciler) ReconcileKind(ctx context.Context, source *sourcesv1alpha1.GitHubSource) pkgreconciler.Event { | |
source.Status.InitializeConditions() | |
accessToken, err := r.secretFrom(ctx, source.Namespace, source.Spec.AccessToken.SecretKeyRef) | |
if err != nil { | |
source.Status.MarkNoSecrets("AccessTokenNotFound", "%s", err) | |
return err | |
} | |
secretToken, err := r.secretFrom(ctx, source.Namespace, source.Spec.SecretToken.SecretKeyRef) | |
if err != nil { | |
source.Status.MarkNoSecrets("SecretTokenNotFound", "%s", err) | |
return err | |
} | |
source.Status.MarkSecrets() | |
dest := source.Spec.Sink.DeepCopy() | |
if dest.Ref != nil { | |
// To call URIFromDestination(), dest.Ref must have a Namespace. If there is | |
// no Namespace defined in dest.Ref, we will use the Namespace of the source | |
// as the Namespace of dest.Ref. | |
if dest.Ref.Namespace == "" { | |
dest.Ref.Namespace = source.GetNamespace() | |
} | |
} | |
uri, err := r.sinkResolver.URIFromDestinationV1(ctx, *dest, source) | |
if err != nil { | |
source.Status.MarkNoSink("NotFound", "%s", err) | |
return err | |
} | |
source.Status.MarkSink(uri) | |
ksvc, err := r.reconcileReceiveAdapter(ctx, source) | |
if err != nil { | |
source.Status.MarkWebhookNotConfigured("MissingReceiveAdapter", err.Error()) | |
return err | |
} | |
if ksvc.Status.GetCondition(apis.ConditionReady).IsTrue() && ksvc.Status.URL != nil { | |
withPath := *ksvc.Status.URL | |
if r.receiveAdapterImage == "" { | |
withPath.Path = fmt.Sprintf("/%s/%s", source.Namespace, source.Name) | |
} | |
args := &webhookArgs{ | |
source: source, | |
url: &withPath, | |
accessToken: accessToken, | |
secretToken: secretToken, | |
alternateGitHubAPIURL: source.Spec.GitHubAPIURL, | |
} | |
// source.Status.MarkServiceDeployed(ra) | |
// TODO: Mark Deployed for the ksvc | |
if source.Status.WebhookIDKey == "" { | |
hookID, err := r.createWebhook(ctx, args) | |
if err != nil { | |
source.Status.MarkWebhookNotConfigured("CreationFailed", err.Error()) | |
return err | |
} | |
source.Status.WebhookIDKey = hookID | |
} else { | |
err := r.reconcileWebhook(ctx, args, source.Status.WebhookIDKey) | |
if err != nil { | |
source.Status.MarkWebhookNotConfigured("ReconciliationFailed", err.Error()) | |
return err | |
} | |
} | |
source.Status.MarkWebhookConfigured() | |
} | |
source.Status.CloudEventAttributes = r.createCloudEventAttributes(source) | |
source.Status.ObservedGeneration = source.Generation | |
return nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment