diff --git a/controllers/complianceeventsapi/server.go b/controllers/complianceeventsapi/server.go index bc5f490c..b08b3887 100644 --- a/controllers/complianceeventsapi/server.go +++ b/controllers/complianceeventsapi/server.go @@ -183,11 +183,11 @@ func postComplianceEvent(db *sql.DB, w http.ResponseWriter, r *http.Request) { } } -func getClusterForeignKey(ctx context.Context, db *sql.DB, cluster Cluster) (int, error) { +func getClusterForeignKey(ctx context.Context, db *sql.DB, cluster Cluster) (int32, error) { // Check cache key, ok := clusterKeyCache.Load(cluster.ClusterID) if ok { - return key.(int), nil + return key.(int32), nil } err := cluster.GetOrCreate(ctx, db) @@ -200,13 +200,13 @@ func getClusterForeignKey(ctx context.Context, db *sql.DB, cluster Cluster) (int return cluster.KeyID, nil } -func getParentPolicyForeignKey(ctx context.Context, db *sql.DB, parent ParentPolicy) (int, error) { +func getParentPolicyForeignKey(ctx context.Context, db *sql.DB, parent ParentPolicy) (int32, error) { // Check cache parKey := parent.key() key, ok := parentPolicyKeyCache.Load(parKey) if ok { - return key.(int), nil + return key.(int32), nil } err := parent.GetOrCreate(ctx, db) @@ -219,7 +219,7 @@ func getParentPolicyForeignKey(ctx context.Context, db *sql.DB, parent ParentPol return parent.KeyID, nil } -func getPolicyForeignKey(ctx context.Context, db *sql.DB, pol Policy) (int, error) { +func getPolicyForeignKey(ctx context.Context, db *sql.DB, pol Policy) (int32, error) { // Fill in missing fields that can be inferred from other fields if pol.SpecHash == "" { var buf bytes.Buffer @@ -236,7 +236,7 @@ func getPolicyForeignKey(ctx context.Context, db *sql.DB, pol Policy) (int, erro key, ok := policyKeyCache.Load(polKey) if ok { - return key.(int), nil + return key.(int32), nil } if pol.Spec == "" { diff --git a/controllers/complianceeventsapi/types.go b/controllers/complianceeventsapi/types.go index 641bd644..977bdd74 100644 --- a/controllers/complianceeventsapi/types.go +++ b/controllers/complianceeventsapi/types.go @@ -87,7 +87,7 @@ func (ce *ComplianceEvent) Create(ctx context.Context, db *sql.DB) error { } type Cluster struct { - KeyID int `db:"id" json:"-"` + KeyID int32 `db:"id" json:"-"` Name string `db:"name" json:"name"` ClusterID string `db:"cluster_id" json:"cluster_id"` //nolint:tagliatelle } @@ -132,10 +132,10 @@ func (c *Cluster) GetOrCreate(ctx context.Context, db *sql.DB) error { } type EventDetails struct { - KeyID int `db:"id" json:"-"` - ClusterID int `db:"cluster_id" json:"-"` - PolicyID int `db:"policy_id" json:"-"` - ParentPolicyID *int `db:"parent_policy_id" json:"-"` + KeyID int32 `db:"id" json:"-"` + ClusterID int32 `db:"cluster_id" json:"-"` + PolicyID int32 `db:"policy_id" json:"-"` + ParentPolicyID *int32 `db:"parent_policy_id" json:"-"` Compliance string `db:"compliance" json:"compliance"` Message string `db:"message" json:"message"` Timestamp time.Time `db:"timestamp" json:"timestamp"` @@ -180,7 +180,7 @@ func (e *EventDetails) InsertQuery() (string, []any) { } type ParentPolicy struct { - KeyID int `db:"id" json:"-"` + KeyID int32 `db:"id" json:"-"` Name string `db:"name" json:"name"` Namespace string `db:"namespace" json:"namespace"` Categories pq.StringArray `db:"categories" json:"categories,omitempty"` @@ -235,7 +235,7 @@ func (p ParentPolicy) key() string { } type Policy struct { - KeyID int `db:"id" json:"-"` + KeyID int32 `db:"id" json:"-"` Kind string `db:"kind" json:"kind"` APIGroup string `db:"api_group" json:"apiGroup"` Name string `db:"name" json:"name"` @@ -381,7 +381,7 @@ func getOrCreate(ctx context.Context, db *sql.DB, obj dbRow) error { return row.Err() } - var primaryKey int + var primaryKey int32 err := row.Scan(&primaryKey) if errors.Is(err, sql.ErrNoRows) {