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

Detect trust bundles changes #3723

Merged
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
8 changes: 8 additions & 0 deletions control-plane/pkg/core/config/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"crypto/x509"
"fmt"
"math"
"sort"

"github.com/rickb777/date/period"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -124,6 +125,13 @@
}
}
}
if len(trustBundles) == 0 {
return nil, nil
}

Check warning on line 130 in control-plane/pkg/core/config/utils.go

View check run for this annotation

Codecov / codecov/patch

control-plane/pkg/core/config/utils.go#L128-L130

Added lines #L128 - L130 were not covered by tests

sort.SliceStable(trustBundles, func(i, j int) bool {
return trustBundles[i] < trustBundles[j]
})

Check warning on line 134 in control-plane/pkg/core/config/utils.go

View check run for this annotation

Codecov / codecov/patch

control-plane/pkg/core/config/utils.go#L132-L134

Added lines #L132 - L134 were not covered by tests
return trustBundles, nil
}

Expand Down
16 changes: 11 additions & 5 deletions control-plane/pkg/reconciler/broker/broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"strings"
"time"

"k8s.io/apimachinery/pkg/api/equality"
"knative.dev/eventing/pkg/auth"
"knative.dev/pkg/logging"

Expand Down Expand Up @@ -172,7 +173,8 @@

logger.Debug("Got contract data from config map", zap.Any(base.ContractLogKey, ct))

if err := r.setTrustBundles(ct); err != nil {
trustBundlesChanged, err := r.setTrustBundles(ct)
if err != nil {
return statusConditionManager.FailedToResolveConfig(err)
}

Expand All @@ -190,7 +192,7 @@

logger.Debug("Change detector", zap.Int("changed", changed))

if changed == coreconfig.ResourceChanged {
if changed == coreconfig.ResourceChanged || trustBundlesChanged {
// Resource changed, increment contract generation.
coreconfig.IncrementContractGeneration(ct)

Expand Down Expand Up @@ -750,11 +752,15 @@
return pointer.String(string(caCerts)), nil
}

func (r *Reconciler) setTrustBundles(ct *contract.Contract) error {
func (r *Reconciler) setTrustBundles(ct *contract.Contract) (bool, error) {
tb, err := coreconfig.TrustBundles(r.ConfigMapLister.ConfigMaps(r.SystemNamespace))
if err != nil {
return fmt.Errorf("failed to get trust bundles: %w", err)
return false, fmt.Errorf("failed to get trust bundles: %w", err)
}

Check warning on line 759 in control-plane/pkg/reconciler/broker/broker.go

View check run for this annotation

Codecov / codecov/patch

control-plane/pkg/reconciler/broker/broker.go#L758-L759

Added lines #L758 - L759 were not covered by tests
changed := false
if !equality.Semantic.DeepEqual(tb, ct.TrustBundles) {
changed = true

Check warning on line 762 in control-plane/pkg/reconciler/broker/broker.go

View check run for this annotation

Codecov / codecov/patch

control-plane/pkg/reconciler/broker/broker.go#L762

Added line #L762 was not covered by tests
}
ct.TrustBundles = tb
return nil
return changed, nil
}
15 changes: 10 additions & 5 deletions control-plane/pkg/reconciler/channel/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,8 @@
}
logger.Debug("Got contract data from config map", zap.Any(base.ContractLogKey, ct))

if err := r.setTrustBundles(ct); err != nil {
trustBundlesChanged, err := r.setTrustBundles(ct)
if err != nil {
return statusConditionManager.FailedToResolveConfig(err)
}

Expand All @@ -256,7 +257,7 @@
changed := coreconfig.AddOrUpdateResourceConfig(ct, channelResource, channelIndex, logger)
logger.Debug("Change detector", zap.Int("changed", changed))

if changed == coreconfig.ResourceChanged || subscribersChanged == coreconfig.EgressChanged {
if changed == coreconfig.ResourceChanged || subscribersChanged == coreconfig.EgressChanged || trustBundlesChanged {
// Resource changed, increment contract generation.
coreconfig.IncrementContractGeneration(ct)

Expand Down Expand Up @@ -808,11 +809,15 @@
return nil
}

func (r *Reconciler) setTrustBundles(ct *contract.Contract) error {
func (r *Reconciler) setTrustBundles(ct *contract.Contract) (bool, error) {
tb, err := coreconfig.TrustBundles(r.ConfigMapLister.ConfigMaps(r.SystemNamespace))
if err != nil {
return fmt.Errorf("failed to get trust bundles: %w", err)
return false, fmt.Errorf("failed to get trust bundles: %w", err)
}

Check warning on line 816 in control-plane/pkg/reconciler/channel/channel.go

View check run for this annotation

Codecov / codecov/patch

control-plane/pkg/reconciler/channel/channel.go#L815-L816

Added lines #L815 - L816 were not covered by tests
changed := false
if !equality.Semantic.DeepEqual(tb, ct.TrustBundles) {
changed = true

Check warning on line 819 in control-plane/pkg/reconciler/channel/channel.go

View check run for this annotation

Codecov / codecov/patch

control-plane/pkg/reconciler/channel/channel.go#L819

Added line #L819 was not covered by tests
}
ct.TrustBundles = tb
return nil
return changed, nil
}
16 changes: 11 additions & 5 deletions control-plane/pkg/reconciler/consumer/consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

"go.uber.org/zap"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/equality"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/client-go/kubernetes"
corelisters "k8s.io/client-go/listers/core/v1"
Expand Down Expand Up @@ -401,11 +402,12 @@
return false, fmt.Errorf("failed to get contract from ConfigMap %s/%s: %w", p.GetNamespace(), cmName, err)
}

if err := r.setTrustBundles(ct); err != nil {
trustBundlesChanged, err := r.setTrustBundles(ct)
if err != nil {
return false, fmt.Errorf("failed to set trust bundles: %w", err)
}

if changed := mutatorFunc(logger, ct, c); changed == coreconfig.ResourceChanged {
if changed := mutatorFunc(logger, ct, c); changed == coreconfig.ResourceChanged || trustBundlesChanged {
logger.Debug("Contract changed", zap.Int("changed", changed))

ct.IncrementGeneration()
Expand Down Expand Up @@ -465,13 +467,17 @@
return false
}

func (r *Reconciler) setTrustBundles(ct *contract.Contract) error {
func (r *Reconciler) setTrustBundles(ct *contract.Contract) (bool, error) {
tb, err := coreconfig.TrustBundles(r.TrustBundleConfigMapLister)
if err != nil {
return fmt.Errorf("failed to get trust bundles: %w", err)
return false, fmt.Errorf("failed to get trust bundles: %w", err)
}

Check warning on line 474 in control-plane/pkg/reconciler/consumer/consumer.go

View check run for this annotation

Codecov / codecov/patch

control-plane/pkg/reconciler/consumer/consumer.go#L473-L474

Added lines #L473 - L474 were not covered by tests
changed := false
if !equality.Semantic.DeepEqual(tb, ct.TrustBundles) {
changed = true

Check warning on line 477 in control-plane/pkg/reconciler/consumer/consumer.go

View check run for this annotation

Codecov / codecov/patch

control-plane/pkg/reconciler/consumer/consumer.go#L477

Added line #L477 was not covered by tests
}
ct.TrustBundles = tb
return nil
return changed, nil
}

type PodStatusSummary struct {
Expand Down
16 changes: 11 additions & 5 deletions control-plane/pkg/reconciler/sink/kafka_sink.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

"github.com/IBM/sarama"
"go.uber.org/zap"
"k8s.io/apimachinery/pkg/api/equality"
"k8s.io/apimachinery/pkg/types"
corelisters "k8s.io/client-go/listers/core/v1"
"k8s.io/client-go/util/retry"
Expand Down Expand Up @@ -174,7 +175,8 @@
ct = &contract.Contract{}
}

if err := r.setTrustBundles(ct); err != nil {
trustBundlesChanged, err := r.setTrustBundles(ct)
if err != nil {
return statusConditionManager.FailedToResolveConfig(err)
}

Expand Down Expand Up @@ -222,7 +224,7 @@
// Update contract data with the new sink configuration.
changed := coreconfig.AddOrUpdateResourceConfig(ct, sinkConfig, sinkIndex, logger)

if changed == coreconfig.ResourceChanged {
if changed == coreconfig.ResourceChanged || trustBundlesChanged {
// Resource changed, increment contract generation.
coreconfig.IncrementContractGeneration(ct)
// Update the configuration map with the new contract data.
Expand Down Expand Up @@ -443,11 +445,15 @@
return pointer.String(string(caCerts)), nil
}

func (r *Reconciler) setTrustBundles(ct *contract.Contract) error {
func (r *Reconciler) setTrustBundles(ct *contract.Contract) (bool, error) {
tb, err := coreconfig.TrustBundles(r.ConfigMapLister.ConfigMaps(r.SystemNamespace))
if err != nil {
return fmt.Errorf("failed to get trust bundles: %w", err)
return false, fmt.Errorf("failed to get trust bundles: %w", err)
}

Check warning on line 452 in control-plane/pkg/reconciler/sink/kafka_sink.go

View check run for this annotation

Codecov / codecov/patch

control-plane/pkg/reconciler/sink/kafka_sink.go#L451-L452

Added lines #L451 - L452 were not covered by tests
changed := false
if !equality.Semantic.DeepEqual(tb, ct.TrustBundles) {
changed = true

Check warning on line 455 in control-plane/pkg/reconciler/sink/kafka_sink.go

View check run for this annotation

Codecov / codecov/patch

control-plane/pkg/reconciler/sink/kafka_sink.go#L455

Added line #L455 was not covered by tests
}
ct.TrustBundles = tb
return nil
return changed, nil
}
Loading