This repository has been archived by the owner on Jun 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 75
/
broker.go
75 lines (60 loc) · 2.61 KB
/
broker.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
Copyright 2020 Google LLC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Package broker implements the Broker controller and reconciler reconciling
// Brokers and Triggers.
package broker
import (
"context"
"fmt"
"github.com/google/knative-gcp/pkg/logging"
"github.com/google/knative-gcp/pkg/reconciler/celltenant"
"go.uber.org/zap"
corev1 "k8s.io/api/core/v1"
pkgreconciler "knative.dev/pkg/reconciler"
brokerv1 "github.com/google/knative-gcp/pkg/apis/broker/v1"
brokerreconciler "github.com/google/knative-gcp/pkg/client/injection/reconciler/broker/v1/broker"
)
const (
// Name of the corev1.Events emitted from the Broker reconciliation process.
brokerReconciled = "BrokerReconciled"
brokerFinalized = "BrokerFinalized"
)
type Reconciler struct {
celltenant.Reconciler
}
// Check that Reconciler implements Interface
var _ brokerreconciler.Interface = (*Reconciler)(nil)
var _ brokerreconciler.Finalizer = (*Reconciler)(nil)
func (r *Reconciler) ReconcileKind(ctx context.Context, b *brokerv1.Broker) pkgreconciler.Event {
logger := logging.FromContext(ctx)
logger.Debug("Reconciling Broker", zap.Any("broker", b))
b.Status.InitializeConditions()
b.Status.ObservedGeneration = b.Generation
bcs := celltenant.StatusableFromBroker(b)
if err := r.Reconciler.ReconcileGCPCellTenant(ctx, bcs); err != nil {
logging.FromContext(ctx).Error("Problem reconciling broker", zap.Error(err))
return fmt.Errorf("failed to reconcile broker: %w", err)
//TODO instead of returning on error, update the data plane configmap with
// whatever info is available. or put this in a defer?
}
return pkgreconciler.NewEvent(corev1.EventTypeNormal, brokerReconciled, "Broker reconciled: \"%s/%s\"", b.Namespace, b.Name)
}
func (r *Reconciler) FinalizeKind(ctx context.Context, b *brokerv1.Broker) pkgreconciler.Event {
logger := logging.FromContext(ctx)
logger.Debug("Finalizing Broker", zap.Any("broker", b))
bcs := celltenant.StatusableFromBroker(b)
if err := r.Reconciler.FinalizeGCPCellTenant(ctx, bcs); err != nil {
return err
}
return pkgreconciler.NewEvent(corev1.EventTypeNormal, brokerFinalized, "Broker finalized: \"%s/%s\"", b.Namespace, b.Name)
}