diff --git a/main.go b/main.go index 1e6800feab7..2318ab85138 100644 --- a/main.go +++ b/main.go @@ -47,11 +47,11 @@ import ( "github.com/open-policy-agent/gatekeeper/v3/pkg/controller" "github.com/open-policy-agent/gatekeeper/v3/pkg/controller/config/process" "github.com/open-policy-agent/gatekeeper/v3/pkg/expansion" + "github.com/open-policy-agent/gatekeeper/v3/pkg/export" "github.com/open-policy-agent/gatekeeper/v3/pkg/externaldata" "github.com/open-policy-agent/gatekeeper/v3/pkg/metrics" "github.com/open-policy-agent/gatekeeper/v3/pkg/mutation" "github.com/open-policy-agent/gatekeeper/v3/pkg/operations" - "github.com/open-policy-agent/gatekeeper/v3/pkg/export" "github.com/open-policy-agent/gatekeeper/v3/pkg/readiness" "github.com/open-policy-agent/gatekeeper/v3/pkg/readiness/pruner" "github.com/open-policy-agent/gatekeeper/v3/pkg/syncutil" diff --git a/pkg/audit/manager.go b/pkg/audit/manager.go index 91f828e0c4a..4e06adde2f9 100644 --- a/pkg/audit/manager.go +++ b/pkg/audit/manager.go @@ -18,11 +18,11 @@ import ( constraintclient "github.com/open-policy-agent/frameworks/constraint/pkg/client" "github.com/open-policy-agent/frameworks/constraint/pkg/client/reviews" "github.com/open-policy-agent/gatekeeper/v3/pkg/controller/config/process" - pubsubController "github.com/open-policy-agent/gatekeeper/v3/pkg/controller/export" + exportController "github.com/open-policy-agent/gatekeeper/v3/pkg/controller/export" "github.com/open-policy-agent/gatekeeper/v3/pkg/expansion" + "github.com/open-policy-agent/gatekeeper/v3/pkg/export" "github.com/open-policy-agent/gatekeeper/v3/pkg/logging" mutationtypes "github.com/open-policy-agent/gatekeeper/v3/pkg/mutation/types" - "github.com/open-policy-agent/gatekeeper/v3/pkg/export" "github.com/open-policy-agent/gatekeeper/v3/pkg/target" "github.com/open-policy-agent/gatekeeper/v3/pkg/util" corev1 "k8s.io/api/core/v1" @@ -107,7 +107,7 @@ type StatusViolation struct { } // ConstraintMsg represents publish message for each constraint. -type PubsubMsg struct { +type ExportMsg struct { ID string `json:"id,omitempty"` Details interface{} `json:"details,omitempty"` EventType string `json:"eventType,omitempty"` @@ -902,10 +902,10 @@ func (am *Manager) addAuditResponsesToUpdateLists( details := r.Metadata["details"] labels := r.obj.GetLabels() logViolation(am.log, constraint, ea, r.ScopedEnforcementActions, gvk, namespace, name, msg, details, labels) - if *pubsubController.ExportEnabled { + if *exportController.ExportEnabled { err := am.exportSystem.Publish(context.Background(), *auditConnection, *auditChannel, violationMsg(constraint, ea, r.ScopedEnforcementActions, gvk, namespace, name, msg, details, labels, timestamp)) if err != nil { - am.log.Error(err, "pubsub audit Publishing") + am.log.Error(err, "export audit Publishing") } } if *emitAuditEvents { @@ -1161,7 +1161,7 @@ func violationMsg(constraint *unstructured.Unstructured, enforcementAction util. userConstraintAnnotations := constraint.GetAnnotations() delete(userConstraintAnnotations, "kubectl.kubernetes.io/last-applied-configuration") - return PubsubMsg{ + return ExportMsg{ Message: message, Details: details, ID: timestamp, diff --git a/pkg/controller/controller.go b/pkg/controller/controller.go index cfb684e518c..ef8872f3581 100644 --- a/pkg/controller/controller.go +++ b/pkg/controller/controller.go @@ -28,9 +28,9 @@ import ( "github.com/open-policy-agent/gatekeeper/v3/pkg/controller/config/process" syncc "github.com/open-policy-agent/gatekeeper/v3/pkg/controller/sync" "github.com/open-policy-agent/gatekeeper/v3/pkg/expansion" + "github.com/open-policy-agent/gatekeeper/v3/pkg/export" "github.com/open-policy-agent/gatekeeper/v3/pkg/fakes" "github.com/open-policy-agent/gatekeeper/v3/pkg/mutation" - "github.com/open-policy-agent/gatekeeper/v3/pkg/export" "github.com/open-policy-agent/gatekeeper/v3/pkg/readiness" "github.com/open-policy-agent/gatekeeper/v3/pkg/util" "github.com/open-policy-agent/gatekeeper/v3/pkg/watch" @@ -58,7 +58,7 @@ type GetPodInjector interface { } type ExportInjector interface { - InjectExportSystem(pubsubSystem *export.System) + InjectExportSystem(exportSystem *export.System) } type DataClientInjector interface { diff --git a/pkg/controller/export/export_config_controller.go b/pkg/controller/export/export_config_controller.go index e73996ad7c3..a0ff7f258a3 100644 --- a/pkg/controller/export/export_config_controller.go +++ b/pkg/controller/export/export_config_controller.go @@ -6,8 +6,8 @@ import ( "flag" "fmt" - "github.com/open-policy-agent/gatekeeper/v3/pkg/logging" "github.com/open-policy-agent/gatekeeper/v3/pkg/export" + "github.com/open-policy-agent/gatekeeper/v3/pkg/logging" "github.com/open-policy-agent/gatekeeper/v3/pkg/readiness" "github.com/open-policy-agent/gatekeeper/v3/pkg/util" "github.com/open-policy-agent/gatekeeper/v3/pkg/watch" @@ -26,8 +26,13 @@ import ( ) var ( +<<<<<<< HEAD ExportEnabled = flag.Bool("enable-pub-sub", false, "(alpha) Enabled pubsub to publish messages") log = logf.Log.WithName("controller").WithValues(logging.Process, "pubsub_controller") +======= + ExportEnabled = flag.Bool("enable-pub-sub", false, "Enable export backend to publish messages") + log = logf.Log.WithName("controller").WithValues(logging.Process, "export_controller") +>>>>>>> fixing errors ) type Adder struct { @@ -46,7 +51,7 @@ func (a *Adder) InjectControllerSwitch(_ *watch.ControllerSwitch) {} func (a *Adder) InjectTracker(_ *readiness.Tracker) {} -func (a *Adder) InjectPubsubSystem(exportSystem *export.System) { +func (a *Adder) InjectExportSystem(exportSystem *export.System) { a.ExportSystem = exportSystem } @@ -65,7 +70,7 @@ func newReconciler(mgr manager.Manager, system *export.System) *Reconciler { } func add(mgr manager.Manager, r reconcile.Reconciler) error { - c, err := controller.New("pubsub-config-controller", mgr, controller.Options{Reconciler: r}) + c, err := controller.New("export-config-controller", mgr, controller.Options{Reconciler: r}) if err != nil { return err } @@ -113,10 +118,10 @@ func (r *Reconciler) Reconcile(ctx context.Context, request reconcile.Request) ( } if len(cfg.Data) == 0 { - return reconcile.Result{}, fmt.Errorf(fmt.Sprintf("data missing in configmap %s, unable to configure respective pubsub", request.NamespacedName)) + return reconcile.Result{}, fmt.Errorf(fmt.Sprintf("data missing in configmap %s, unable to establish connection", request.NamespacedName)) } if _, ok := cfg.Data["driver"]; !ok { - return reconcile.Result{}, fmt.Errorf(fmt.Sprintf("missing driver field in configmap %s, unable to configure respective pubsub", request.NamespacedName)) + return reconcile.Result{}, fmt.Errorf(fmt.Sprintf("missing driver field in configmap %s, unable to establish connection", request.NamespacedName)) } var config interface{} err = json.Unmarshal([]byte(cfg.Data["config"]), &config) diff --git a/pkg/controller/export/export_config_controller_test.go b/pkg/controller/export/export_config_controller_test.go index 2af36022bf4..8f4c599f8c8 100644 --- a/pkg/controller/export/export_config_controller_test.go +++ b/pkg/controller/export/export_config_controller_test.go @@ -48,7 +48,7 @@ func TestReconcile(t *testing.T) { }, }, wantErr: true, - errorMsg: fmt.Sprintf("data missing in configmap %s, unable to configure respective pubsub", request.NamespacedName), + errorMsg: fmt.Sprintf("data missing in configmap %s, unable to configure respective driver", request.NamespacedName), }, } for _, tc := range testCases { diff --git a/pkg/export/dapr/dapr.go b/pkg/export/dapr/dapr.go index 095ffbba994..2c57c927fb6 100644 --- a/pkg/export/dapr/dapr.go +++ b/pkg/export/dapr/dapr.go @@ -24,7 +24,9 @@ const ( Name = "dapr" ) -var Connections = &Dapr{} +var Connections = &Dapr{ + openConnections: make(map[string]Connection), +} func (r *Dapr) Publish(_ context.Context, connectionName string, data interface{}, topic string) error { jsonData, err := json.Marshal(data) diff --git a/test/pubsub/fake-subscriber/main.go b/test/pubsub/fake-subscriber/main.go index fadd3aac2c9..96271c8a4d7 100644 --- a/test/pubsub/fake-subscriber/main.go +++ b/test/pubsub/fake-subscriber/main.go @@ -11,7 +11,7 @@ import ( daprd "github.com/dapr/go-sdk/service/http" ) -type PubsubMsg struct { +type ExportMsg struct { ID string `json:"id,omitempty"` Details interface{} `json:"details,omitempty"` EventType string `json:"eventType,omitempty"` @@ -52,7 +52,7 @@ func main() { } func eventHandler(_ context.Context, e *common.TopicEvent) (retry bool, err error) { - var msg PubsubMsg + var msg ExportMsg jsonInput, err := strconv.Unquote(string(e.RawData)) if err != nil { log.Fatalf("error unquoting %v", err) diff --git a/test/pubsub/publish-components.yaml b/test/pubsub/publish-components.yaml index 9686935dd01..e623acabe6f 100644 --- a/test/pubsub/publish-components.yaml +++ b/test/pubsub/publish-components.yaml @@ -21,7 +21,7 @@ metadata: name: audit namespace: gatekeeper-system data: - provider: "dapr" + driver: "dapr" config: | { "component": "pubsub"