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

[release-v1.12] Detect trust bundles changes #1065

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 @@ import (
"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 @@ func TrustBundles(lister corev1listers.ConfigMapNamespaceLister) ([]string, erro
}
}
}
if len(trustBundles) == 0 {
return nil, nil
}

sort.SliceStable(trustBundles, func(i, j int) bool {
return trustBundles[i] < trustBundles[j]
})
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 @@ -27,6 +27,7 @@ import (

"go.uber.org/zap"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/equality"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
Expand Down Expand Up @@ -172,7 +173,8 @@ func (r *Reconciler) reconcileKind(ctx context.Context, broker *eventing.Broker)

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 @@ func (r *Reconciler) reconcileKind(ctx context.Context, broker *eventing.Broker)

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 @@ -741,11 +743,15 @@ func (r *Reconciler) getCaCerts() (*string, error) {
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)
}
changed := false
if !equality.Semantic.DeepEqual(tb, ct.TrustBundles) {
changed = true
}
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 @@ func (r *Reconciler) reconcileKind(ctx context.Context, channel *messagingv1beta
}
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 @@ func (r *Reconciler) reconcileKind(ctx context.Context, channel *messagingv1beta
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 @@ func findSubscriptionStatus(kc *messagingv1beta1.KafkaChannel, subUID types.UID)
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)
}
changed := false
if !equality.Semantic.DeepEqual(tb, ct.TrustBundles) {
changed = true
}
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 @@ -22,6 +22,7 @@ import (

"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 @@ -383,11 +384,12 @@ func (r *Reconciler) schedule(ctx context.Context, logger *zap.Logger, c *kafkai
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 @@ -447,11 +449,15 @@ func FalseAnyStatus(*corev1.Pod) bool {
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)
}
changed := false
if !equality.Semantic.DeepEqual(tb, ct.TrustBundles) {
changed = true
}
ct.TrustBundles = tb
return nil
return changed, nil
}
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 @@ import (

"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 @@ func (r *Reconciler) reconcileKind(ctx context.Context, ks *eventing.KafkaSink)
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 @@ func (r *Reconciler) reconcileKind(ctx context.Context, ks *eventing.KafkaSink)
// 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 @@ func (r *Reconciler) getCaCerts() (*string, error) {
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)
}
changed := false
if !equality.Semantic.DeepEqual(tb, ct.TrustBundles) {
changed = true
}
ct.TrustBundles = tb
return nil
return changed, nil
}