Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip service principal enrichment for MIWI clusters #3971

Merged
merged 1 commit into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions pkg/util/clusterdata/clusterdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,17 @@ func (p ParallelEnricher) enrichOne(ctx context.Context, log *logrus.Entry, oc *
return
}

errors := make(chan error, len(p.enrichers))
numEnrichers := len(p.enrichers)

// We skip the service principal enricher for workload identity clusters
if oc.UsesWorkloadIdentity() {
numEnrichers = numEnrichers - 1
}

errors := make(chan error, numEnrichers)
expectedResults := 0
for name, enricher := range p.enrichers {
if unsuccessfulEnrichers[name] || enricher == nil {
if unsuccessfulEnrichers[name] || enricher == nil || (name == servicePrincipal && oc.UsesWorkloadIdentity()) {
continue
}
p.emitter.EmitGauge("enricher.tasks.count", 1, nil)
Expand Down
81 changes: 53 additions & 28 deletions pkg/util/clusterdata/clusterdata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,52 +23,69 @@ func TestEnrichOne(t *testing.T) {
enricherName := "enricherName"

for _, tt := range []struct {
name string
failedEnrichers map[string]bool
taskCount int
taskDuration int
timeoutCount int
errorCount int
enricherCallCount int
enricherReturnValue error
enricherIsNil bool
name string
failedEnrichers map[string]bool
taskCount int
taskDuration int
timeoutCount int
errorCount int
enricherCallCount int
enricherReturnValue error
enricherIsNil bool
usesWorkloadIdentity bool
}{
{
name: "enricher called",
enricherCallCount: 1,
name: "all enrichers called for service principal cluster",
enricherCallCount: 2,
enricherReturnValue: nil,
taskCount: 1,
taskDuration: 1,
taskCount: 2,
taskDuration: 2,
failedEnrichers: map[string]bool{enricherName: false},
},
{
name: "enricher not called because failed",
enricherCallCount: 0,
failedEnrichers: map[string]bool{enricherName: true},
name: "service principal enricher skipped for workload identity cluster",
enricherCallCount: 1,
enricherReturnValue: nil,
taskCount: 1,
taskDuration: 1,
failedEnrichers: map[string]bool{enricherName: false},
usesWorkloadIdentity: true,
},
{
name: "enricher not called because failed",
enricherCallCount: 1,
enricherReturnValue: nil,
taskCount: 1,
taskDuration: 1,
failedEnrichers: map[string]bool{enricherName: true},
},
{
//should just not panic
name: "enricher not called because nil",
failedEnrichers: map[string]bool{enricherName: false},
enricherIsNil: true,
name: "enricher not called because nil",
enricherCallCount: 1,
enricherReturnValue: nil,
taskCount: 1,
taskDuration: 1,
failedEnrichers: map[string]bool{enricherName: false},
enricherIsNil: true,
},
{
name: "enricher timeout",
enricherCallCount: 1,
enricherCallCount: 2,
enricherReturnValue: context.DeadlineExceeded,
failedEnrichers: map[string]bool{enricherName: false},
taskCount: 1,
taskDuration: 1,
taskCount: 2,
taskDuration: 2,
timeoutCount: 1,
},
{
name: "enricher error",
enricherCallCount: 1,
enricherCallCount: 2,
enricherReturnValue: errors.New("some error"),
failedEnrichers: map[string]bool{enricherName: false},
taskCount: 1,
taskDuration: 1,
errorCount: 1,
taskCount: 2,
taskDuration: 2,
errorCount: 2,
},
} {
t.Run(tt.name, func(t *testing.T) {
Expand All @@ -89,16 +106,24 @@ func TestEnrichOne(t *testing.T) {
e := ParallelEnricher{
emitter: metricsMock,
enrichers: map[string]ClusterEnricher{
enricherName: enricherMock,
enricherName: enricherMock,
servicePrincipal: enricherMock,
},
metricsWG: &sync.WaitGroup{},
}
if tt.enricherIsNil {
e.enrichers[enricherName] = nil
}

oc := &api.OpenShiftCluster{}
if tt.usesWorkloadIdentity {
oc.Properties.PlatformWorkloadIdentityProfile = &api.PlatformWorkloadIdentityProfile{}
} else {
oc.Properties.ServicePrincipalProfile = &api.ServicePrincipalProfile{}
}

ctx := context.Background()
e.enrichOne(ctx, log, &api.OpenShiftCluster{}, clients{}, tt.failedEnrichers)
e.enrichOne(ctx, log, oc, clients{}, tt.failedEnrichers)

e.metricsWG.Wait()
})
Expand Down
Loading