Skip to content

Commit e188f14

Browse files
feat: add OCIRepositoryAdapter
1 parent 477d95e commit e188f14

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed

pkg/juggler/fluxcd/flux_sources.go

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,3 +163,75 @@ func (g *GitRepositoryAdapter) ApplyDefaults() {
163163

164164
g.Source.Spec.Interval = metav1.Duration{Duration: 1 * time.Hour}
165165
}
166+
167+
//
168+
// -----------------------------------
169+
//
170+
171+
var _ SourceAdapter = &OCIRepositoryAdapter{}
172+
173+
// OCIRepositoryAdapter implements SourceAdapter
174+
type OCIRepositoryAdapter struct {
175+
Source *sourcev1.OCIRepository
176+
}
177+
178+
// ApplyDefaults implements SourceAdapter.
179+
func (o *OCIRepositoryAdapter) ApplyDefaults() {
180+
// This usually does nothing but we can keep it here in case Flux resources will have
181+
// a defaulting func in the future.
182+
scheme.Default(o.Source)
183+
184+
o.Source.Spec.Interval = metav1.Duration{Duration: 1 * time.Hour}
185+
}
186+
187+
// Empty implements SourceAdapter.
188+
func (o *OCIRepositoryAdapter) Empty() SourceAdapter {
189+
return &OCIRepositoryAdapter{&sourcev1.OCIRepository{
190+
ObjectMeta: metav1.ObjectMeta{
191+
Name: o.Source.Name,
192+
Namespace: o.Source.Namespace,
193+
},
194+
}}
195+
}
196+
197+
// GetHealthiness implements SourceAdapter.
198+
func (o *OCIRepositoryAdapter) GetHealthiness() juggler.ResourceHealthiness {
199+
cond := apimeta.FindStatusCondition(o.Source.Status.Conditions, fluxmeta.ReadyCondition)
200+
if cond == nil {
201+
return juggler.ResourceHealthiness{
202+
Healthy: false,
203+
Message: msgReadyNotPresent,
204+
}
205+
}
206+
return juggler.ResourceHealthiness{
207+
Healthy: cond.Status == metav1.ConditionTrue,
208+
Message: cond.Message,
209+
}
210+
}
211+
212+
// GetObject implements SourceAdapter.
213+
func (o *OCIRepositoryAdapter) GetObject() client.Object {
214+
return o.Source
215+
}
216+
217+
// GetObjectKey implements SourceAdapter.
218+
func (o *OCIRepositoryAdapter) GetObjectKey() client.ObjectKey {
219+
return client.ObjectKey{
220+
Namespace: o.Source.Namespace,
221+
Name: o.Source.Name,
222+
}
223+
}
224+
225+
// Reconcile implements SourceAdapter.
226+
func (o *OCIRepositoryAdapter) Reconcile(desired FluxResource) error {
227+
desiredAdapter, ok := desired.(*OCIRepositoryAdapter)
228+
if !ok {
229+
return errNotAGitRepositoryAdapter
230+
}
231+
232+
preserved := o.Source.Spec.DeepCopy()
233+
o.Source.Spec = desiredAdapter.Source.Spec
234+
// Give suspension precedence
235+
o.Source.Spec.Suspend = preserved.Suspend
236+
return nil
237+
}

0 commit comments

Comments
 (0)