Skip to content

Commit ac29e09

Browse files
committed
Addressing latest round of PR feedback
Signed-off-by: Tayler Geiger <[email protected]>
1 parent 44f58a0 commit ac29e09

File tree

4 files changed

+48
-17
lines changed

4 files changed

+48
-17
lines changed

.golangci.yaml

-4
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@ run:
1616
# Default timeout is 1m, up to give more room
1717
timeout: 4m
1818

19-
issues:
20-
exclude-dirs:
21-
- internal/operator-controller/authorization/internal/kubernetes
22-
2319
linters:
2420
enable:
2521
- asciicheck

codecov.yml

-2
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,3 @@ coverage:
1010
- "cmd/"
1111
- "internal/"
1212

13-
ignore:
14-
- "internal/operator-controller/authorization/internal/kubernetes"

internal/operator-controller/applier/helm_test.go

+44-9
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,13 @@ import (
1717
"helm.sh/helm/v3/pkg/storage/driver"
1818
corev1 "k8s.io/api/core/v1"
1919
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
20-
featuregatetesting "k8s.io/component-base/featuregate/testing"
2120
"sigs.k8s.io/controller-runtime/pkg/client"
2221

2322
helmclient "github.com/operator-framework/helm-operator-plugins/pkg/client"
2423

2524
ocv1 "github.com/operator-framework/operator-controller/api/v1"
2625
"github.com/operator-framework/operator-controller/internal/operator-controller/applier"
2726
"github.com/operator-framework/operator-controller/internal/operator-controller/authorization"
28-
"github.com/operator-framework/operator-controller/internal/operator-controller/features"
2927
"github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/convert"
3028
)
3129

@@ -45,6 +43,17 @@ func (p *noOpPreAuthorizer) PreAuthorize(
4543
return nil, nil
4644
}
4745

46+
type errorPreAuthorizer struct{}
47+
48+
func (p *errorPreAuthorizer) PreAuthorize(
49+
ctx context.Context,
50+
ext *ocv1.ClusterExtension,
51+
manifestReader io.Reader,
52+
) ([]authorization.ScopedPolicyRules, error) {
53+
// Always returns no missing rules and an error
54+
return nil, errors.New("problem running preauthorization")
55+
}
56+
4857
func (mp *mockPreflight) Install(context.Context, *release.Release) error {
4958
return mp.installErr
5059
}
@@ -270,7 +279,6 @@ func TestApply_Installation(t *testing.T) {
270279
}
271280

272281
func TestApply_InstallationWithPreflightPermissionsEnabled(t *testing.T) {
273-
featuregatetesting.SetFeatureGateDuringTest(t, features.OperatorControllerFeatureGate, features.PreflightPermissions, true)
274282

275283
t.Run("fails during dry-run installation", func(t *testing.T) {
276284
mockAcg := &mockActionGetter{
@@ -313,18 +321,17 @@ func TestApply_InstallationWithPreflightPermissionsEnabled(t *testing.T) {
313321
require.Nil(t, objs)
314322
})
315323

316-
t.Run("fails during installation", func(t *testing.T) {
324+
t.Run("fails during installation because of missing RBAC rules", func(t *testing.T) {
317325
mockAcg := &mockActionGetter{
318326
getClientErr: driver.ErrReleaseNotFound,
319-
installErr: errors.New("failed installing chart"),
320327
desiredRel: &release.Release{
321328
Info: &release.Info{Status: release.StatusDeployed},
322329
Manifest: validManifest,
323330
},
324331
}
325332
helmApplier := applier.Helm{
326333
ActionClientGetter: mockAcg,
327-
PreAuthorizer: &noOpPreAuthorizer{},
334+
PreAuthorizer: &errorPreAuthorizer{},
328335
BundleToHelmChartFn: convert.RegistryV1ToHelmChart,
329336
}
330337
// Use a ClusterExtension with valid Spec fields.
@@ -338,8 +345,37 @@ func TestApply_InstallationWithPreflightPermissionsEnabled(t *testing.T) {
338345
}
339346
objs, state, err := helmApplier.Apply(context.TODO(), validFS, validCE, testObjectLabels, testStorageLabels)
340347
require.Error(t, err)
341-
require.ErrorContains(t, err, "installing chart")
342-
require.Equal(t, applier.StateNeedsInstall, state)
348+
require.ErrorContains(t, err, "problem running preauthorization")
349+
require.Equal(t, "", state)
350+
require.Nil(t, objs)
351+
})
352+
353+
t.Run("fails during installation because of pre-authorization failure", func(t *testing.T) {
354+
mockAcg := &mockActionGetter{
355+
getClientErr: driver.ErrReleaseNotFound,
356+
desiredRel: &release.Release{
357+
Info: &release.Info{Status: release.StatusDeployed},
358+
Manifest: validManifest,
359+
},
360+
}
361+
helmApplier := applier.Helm{
362+
ActionClientGetter: mockAcg,
363+
PreAuthorizer: &errorPreAuthorizer{},
364+
BundleToHelmChartFn: convert.RegistryV1ToHelmChart,
365+
}
366+
// Use a ClusterExtension with valid Spec fields.
367+
validCE := &ocv1.ClusterExtension{
368+
Spec: ocv1.ClusterExtensionSpec{
369+
Namespace: "default",
370+
ServiceAccount: ocv1.ServiceAccountReference{
371+
Name: "default",
372+
},
373+
},
374+
}
375+
objs, state, err := helmApplier.Apply(context.TODO(), validFS, validCE, testObjectLabels, testStorageLabels)
376+
require.Error(t, err)
377+
require.ErrorContains(t, err, "problem running preauthorization")
378+
require.Equal(t, "", state)
343379
require.Nil(t, objs)
344380
})
345381

@@ -488,7 +524,6 @@ func TestApply_Upgrade(t *testing.T) {
488524
}
489525

490526
func TestApply_InstallationWithSingleOwnNamespaceInstallSupportEnabled(t *testing.T) {
491-
featuregatetesting.SetFeatureGateDuringTest(t, features.OperatorControllerFeatureGate, features.SingleOwnNamespaceInstallSupport, true)
492527

493528
t.Run("generates bundle resources using the configured watch namespace", func(t *testing.T) {
494529
var expectedWatchNamespace = "watch-namespace"

internal/operator-controller/features/features.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package features
22

33
import (
4+
"fmt"
45
"sort"
56

67
"github.com/go-logr/logr"
@@ -51,8 +52,9 @@ func LogFeatureGateStates(log logr.Logger, fg featuregate.FeatureGate) {
5152
return string(featureKeys[i]) < string(featureKeys[j]) // Sort by string representation
5253
})
5354

54-
log.Info("Feature Gates Status:")
55+
featurePairs := make([]string, 0, len(featureKeys))
5556
for _, feature := range featureKeys {
56-
log.Info(" ", "feature", string(feature), "enabled", fg.Enabled(feature))
57+
featurePairs = append(featurePairs, string(feature), fmt.Sprintf("%v", fg.Enabled(feature)))
5758
}
59+
log.Info("feature gate status", featurePairs)
5860
}

0 commit comments

Comments
 (0)