Skip to content

Commit

Permalink
fixing errors
Browse files Browse the repository at this point in the history
Signed-off-by: Jaydip Gabani <[email protected]>
  • Loading branch information
JaydipGabani committed Oct 16, 2024
1 parent e0f0de7 commit 570505d
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 20 deletions.
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
12 changes: 6 additions & 6 deletions pkg/audit/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"`
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -58,7 +58,7 @@ type GetPodInjector interface {
}

type ExportInjector interface {
InjectExportSystem(pubsubSystem *export.System)
InjectExportSystem(exportSystem *export.System)
}

type DataClientInjector interface {
Expand Down
12 changes: 6 additions & 6 deletions pkg/controller/export/export_config_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -27,7 +27,7 @@ import (

var (
ExportEnabled = flag.Bool("enable-pub-sub", false, "Enable export backend to publish messages")
log = logf.Log.WithName("controller").WithValues(logging.Process, "pubsub_controller")
log = logf.Log.WithName("controller").WithValues(logging.Process, "export_controller")
)

type Adder struct {
Expand All @@ -46,7 +46,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
}

Expand All @@ -65,7 +65,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
}
Expand Down Expand Up @@ -113,10 +113,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)
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/export/export_config_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 3 additions & 1 deletion pkg/export/dapr/dapr.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions test/pubsub/fake-subscriber/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion test/pubsub/publish-components.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ metadata:
name: audit
namespace: gatekeeper-system
data:
provider: "dapr"
driver: "dapr"
config: |
{
"component": "pubsub"
Expand Down

0 comments on commit 570505d

Please sign in to comment.