Skip to content

Commit

Permalink
Allow cross-shard dependency check
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
  • Loading branch information
stefanprodan committed Sep 25, 2024
1 parent 754c2ba commit edc681c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
3 changes: 2 additions & 1 deletion internal/controller/helmrelease_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ type HelmReleaseReconciler struct {
GetClusterConfig func() (*rest.Config, error)
ClientOpts runtimeClient.Options
KubeConfigOpts runtimeClient.KubeConfigOptions
APIReader client.Reader

FieldManager string
DefaultServiceAccount string
Expand Down Expand Up @@ -585,7 +586,7 @@ func (r *HelmReleaseReconciler) checkDependencies(ctx context.Context, obj *v2.H
}

dHr := &v2.HelmRelease{}
if err := r.Get(ctx, ref, dHr); err != nil {
if err := r.APIReader.Get(ctx, ref, dHr); err != nil {
return fmt.Errorf("unable to get '%s' dependency: %w", ref, err)
}

Expand Down
21 changes: 20 additions & 1 deletion internal/controller/helmrelease_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ func TestHelmReleaseReconciler_reconcileRelease(t *testing.T) {
EventRecorder: record.NewFakeRecorder(32),
requeueDependency: 5 * time.Second,
}
r.APIReader = r.Client

res, err := r.reconcileRelease(context.TODO(), patch.NewSerialPatcher(obj, r.Client), obj)
g.Expect(err).To(Equal(errWaitForDependency))
Expand Down Expand Up @@ -142,6 +143,7 @@ func TestHelmReleaseReconciler_reconcileRelease(t *testing.T) {
WithObjects(obj).
Build(),
}
r.APIReader = r.Client

_, err := r.reconcileRelease(context.TODO(), patch.NewSerialPatcher(obj, r.Client), obj)
g.Expect(err).To(HaveOccurred())
Expand Down Expand Up @@ -173,6 +175,7 @@ func TestHelmReleaseReconciler_reconcileRelease(t *testing.T) {
Build(),
EventRecorder: record.NewFakeRecorder(32),
}
r.APIReader = r.Client

res, err := r.reconcileRelease(context.TODO(), patch.NewSerialPatcher(obj, r.Client), obj)
g.Expect(err).To(HaveOccurred())
Expand Down Expand Up @@ -286,6 +289,7 @@ func TestHelmReleaseReconciler_reconcileRelease(t *testing.T) {
WithObjects(chart, obj).
Build(),
}
r.APIReader = r.Client

res, err := r.reconcileRelease(context.TODO(), patch.NewSerialPatcher(obj, r.Client), obj)
g.Expect(err).To(Equal(errWaitForChart))
Expand Down Expand Up @@ -347,6 +351,7 @@ func TestHelmReleaseReconciler_reconcileRelease(t *testing.T) {
Build(),
EventRecorder: record.NewFakeRecorder(32),
}
r.APIReader = r.Client

_, err := r.reconcileRelease(context.TODO(), patch.NewSerialPatcher(obj, r.Client), obj)
g.Expect(err).To(HaveOccurred())
Expand Down Expand Up @@ -398,6 +403,7 @@ func TestHelmReleaseReconciler_reconcileRelease(t *testing.T) {
Build(),
requeueDependency: 10 * time.Second,
}
r.APIReader = r.Client

res, err := r.reconcileRelease(context.TODO(), patch.NewSerialPatcher(obj, r.Client), obj)
g.Expect(err).To(Equal(errWaitForDependency))
Expand Down Expand Up @@ -486,6 +492,7 @@ func TestHelmReleaseReconciler_reconcileRelease(t *testing.T) {

r := &HelmReleaseReconciler{
Client: c,
APIReader: c,
GetClusterConfig: GetTestClusterConfig,
EventRecorder: record.NewFakeRecorder(32),
}
Expand Down Expand Up @@ -566,6 +573,7 @@ func TestHelmReleaseReconciler_reconcileRelease(t *testing.T) {

r := &HelmReleaseReconciler{
Client: c,
APIReader: c,
GetClusterConfig: GetTestClusterConfig,
EventRecorder: record.NewFakeRecorder(32),
}
Expand Down Expand Up @@ -641,6 +649,7 @@ func TestHelmReleaseReconciler_reconcileRelease(t *testing.T) {

r := &HelmReleaseReconciler{
Client: c,
APIReader: c,
GetClusterConfig: GetTestClusterConfig,
EventRecorder: record.NewFakeRecorder(32),
}
Expand Down Expand Up @@ -712,6 +721,7 @@ func TestHelmReleaseReconciler_reconcileRelease(t *testing.T) {

r := &HelmReleaseReconciler{
Client: c,
APIReader: c,
GetClusterConfig: GetTestClusterConfig,
EventRecorder: record.NewFakeRecorder(32),
}
Expand Down Expand Up @@ -801,6 +811,7 @@ func TestHelmReleaseReconciler_reconcileRelease(t *testing.T) {

r := &HelmReleaseReconciler{
Client: c,
APIReader: c,
GetClusterConfig: GetTestClusterConfig,
EventRecorder: record.NewFakeRecorder(32),
FieldManager: "test",
Expand Down Expand Up @@ -2127,6 +2138,7 @@ func TestHelmReleaseReconciler_reconcileDelete(t *testing.T) {

r := &HelmReleaseReconciler{
Client: testEnv.Client,
APIReader: testEnv.Client,
GetClusterConfig: GetTestClusterConfig,
EventRecorder: record.NewFakeRecorder(32),
}
Expand Down Expand Up @@ -2237,6 +2249,7 @@ func TestHelmReleaseReconciler_reconcileReleaseDeletion(t *testing.T) {

r := &HelmReleaseReconciler{
Client: testEnv.Client,
APIReader: testEnv.Client,
GetClusterConfig: GetTestClusterConfig,
EventRecorder: record.NewFakeRecorder(32),
}
Expand Down Expand Up @@ -2299,6 +2312,7 @@ func TestHelmReleaseReconciler_reconcileReleaseDeletion(t *testing.T) {

r := &HelmReleaseReconciler{
Client: testEnv.Client,
APIReader: testEnv.Client,
GetClusterConfig: GetTestClusterConfig,
}

Expand Down Expand Up @@ -2399,6 +2413,7 @@ func TestHelmReleaseReconciler_reconcileReleaseDeletion(t *testing.T) {

r := &HelmReleaseReconciler{
Client: testEnv.Client,
APIReader: testEnv.Client,
GetClusterConfig: GetTestClusterConfig,
}

Expand Down Expand Up @@ -2526,6 +2541,7 @@ func TestHelmReleaseReconciler_reconcileReleaseDeletion(t *testing.T) {

r := &HelmReleaseReconciler{
Client: testEnv.Client,
APIReader: testEnv.Client,
GetClusterConfig: GetTestClusterConfig,
}

Expand Down Expand Up @@ -2668,6 +2684,7 @@ func TestHelmReleaseReconciler_reconcileUninstall(t *testing.T) {

r := &HelmReleaseReconciler{
Client: testEnv.Client,
APIReader: testEnv.Client,
GetClusterConfig: GetTestClusterConfig,
EventRecorder: record.NewFakeRecorder(32),
}
Expand Down Expand Up @@ -2886,7 +2903,8 @@ func TestHelmReleaseReconciler_checkDependencies(t *testing.T) {
}

r := &HelmReleaseReconciler{
Client: c.Build(),
Client: c.Build(),
APIReader: c.Build(),
}

err := r.checkDependencies(context.TODO(), tt.obj)
Expand Down Expand Up @@ -3029,6 +3047,7 @@ func TestHelmReleaseReconciler_adoptLegacyRelease(t *testing.T) {

r := &HelmReleaseReconciler{
Client: testEnv.Client,
APIReader: testEnv.Client,
GetClusterConfig: GetTestClusterConfig,
}

Expand Down
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ func main() {

if err = (&controller.HelmReleaseReconciler{
Client: mgr.GetClient(),
APIReader: mgr.GetAPIReader(),
EventRecorder: eventRecorder,
Metrics: metricsH,
GetClusterConfig: ctrl.GetConfig,
Expand Down

0 comments on commit edc681c

Please sign in to comment.