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

Favorites feature #158

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions pkg/schema/v1/cron_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type CronJob struct {
Annotations []Annotation `db:"-"`
CronJobAnnotations []CronJobAnnotation `db:"-"`
ResourceAnnotations []ResourceAnnotation `db:"-"`
Favorites []Favorite `db:"-"`
}

type CronJobLabel struct {
Expand Down Expand Up @@ -129,5 +130,6 @@ func (c *CronJob) Relations() []database.Relation {
database.HasMany(c.ResourceAnnotations, database.WithForeignKey("resource_uuid")),
database.HasMany(c.Annotations, database.WithoutCascadeDelete()),
database.HasMany(c.CronJobAnnotations, fk),
database.HasMany(c.Favorites, database.WithForeignKey("resource_uuid")),
}
}
2 changes: 2 additions & 0 deletions pkg/schema/v1/daemon_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type DaemonSet struct {
Annotations []Annotation `db:"-"`
DaemonSetAnnotations []DaemonSetAnnotation `db:"-"`
ResourceAnnotations []ResourceAnnotation `db:"-"`
Favorites []Favorite `db:"-"`
}

type DaemonSetCondition struct {
Expand Down Expand Up @@ -216,5 +217,6 @@ func (d *DaemonSet) Relations() []database.Relation {
database.HasMany(d.ResourceAnnotations, database.WithForeignKey("resource_uuid")),
database.HasMany(d.Annotations, database.WithoutCascadeDelete()),
database.HasMany(d.DaemonSetAnnotations, fk),
database.HasMany(d.Favorites, database.WithForeignKey("resource_uuid")),
}
}
2 changes: 2 additions & 0 deletions pkg/schema/v1/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type Deployment struct {
Annotations []Annotation `db:"-"`
DeploymentAnnotations []DeploymentAnnotation `db:"-"`
ResourceAnnotations []ResourceAnnotation `db:"-"`
Favorites []Favorite `db:"-"`
}

type DeploymentCondition struct {
Expand Down Expand Up @@ -235,5 +236,6 @@ func (d *Deployment) Relations() []database.Relation {
database.HasMany(d.ResourceAnnotations, database.WithForeignKey("resource_uuid")),
database.HasMany(d.Annotations, database.WithoutCascadeDelete()),
database.HasMany(d.DeploymentAnnotations, fk),
database.HasMany(d.Favorites, database.WithForeignKey("resource_uuid")),
}
}
8 changes: 8 additions & 0 deletions pkg/schema/v1/favorite.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package v1

import "github.com/icinga/icinga-go-library/types"

type Favorite struct {
ResourceUuid types.UUID
Username string
}
2 changes: 2 additions & 0 deletions pkg/schema/v1/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type Ingress struct {
Annotations []Annotation `db:"-"`
IngressAnnotations []IngressAnnotation `db:"-"`
ResourceAnnotations []ResourceAnnotation `db:"-"`
Favorites []Favorite `db:"-"`
}

type IngressTls struct {
Expand Down Expand Up @@ -228,5 +229,6 @@ func (i *Ingress) Relations() []database.Relation {
database.HasMany(i.ResourceAnnotations, database.WithForeignKey("resource_uuid")),
database.HasMany(i.Annotations, database.WithoutCascadeDelete()),
database.HasMany(i.IngressAnnotations, fk),
database.HasMany(i.Favorites, database.WithForeignKey("resource_uuid")),
}
}
2 changes: 2 additions & 0 deletions pkg/schema/v1/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type Job struct {
JobAnnotations []JobAnnotation `db:"-"`
ResourceAnnotations []ResourceAnnotation `db:"-"`
Owners []JobOwner `db:"-"`
Favorites []Favorite `db:"-"`
}

type JobCondition struct {
Expand Down Expand Up @@ -287,5 +288,6 @@ func (j *Job) Relations() []database.Relation {
database.HasMany(j.Annotations, database.WithoutCascadeDelete()),
database.HasMany(j.JobAnnotations, fk),
database.HasMany(j.Owners, fk),
database.HasMany(j.Favorites, database.WithForeignKey("resource_uuid")),
}
}
2 changes: 2 additions & 0 deletions pkg/schema/v1/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type Namespace struct {
Annotations []Annotation `db:"-"`
NamespaceAnnotations []NamespaceAnnotation `db:"-"`
ResourceAnnotations []ResourceAnnotation `db:"-"`
Favorites []Favorite `db:"-"`
}

type NamespaceCondition struct {
Expand Down Expand Up @@ -117,5 +118,6 @@ func (n *Namespace) Relations() []database.Relation {
database.HasMany(n.ResourceAnnotations, database.WithForeignKey("resource_uuid")),
database.HasMany(n.Annotations, database.WithoutCascadeDelete()),
database.HasMany(n.NamespaceAnnotations, fk),
database.HasMany(n.Favorites, database.WithForeignKey("resource_uuid")),
}
}
2 changes: 2 additions & 0 deletions pkg/schema/v1/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ type Node struct {
Annotations []Annotation `db:"-"`
NodeAnnotations []NodeAnnotation `db:"-"`
ResourceAnnotations []ResourceAnnotation `db:"-"`
Favorites []Favorite `db:"-"`
}

type NodeCondition struct {
Expand Down Expand Up @@ -282,6 +283,7 @@ func (n *Node) Relations() []database.Relation {
database.HasMany(n.ResourceAnnotations, database.WithForeignKey("resource_uuid")),
database.HasMany(n.Annotations, database.WithoutCascadeDelete()),
database.HasMany(n.NodeAnnotations, fk),
database.HasMany(n.Favorites, database.WithForeignKey("resource_uuid")),
}
}

Expand Down
2 changes: 2 additions & 0 deletions pkg/schema/v1/persistent_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type PersistentVolume struct {
Annotations []Annotation `db:"-"`
PersistentVolumeAnnotations []PersistentVolumeAnnotation `db:"-"`
ResourceAnnotations []PersistentVolumeAnnotation `db:"-"`
Favorites []Favorite `db:"-"`
}

type PersistentVolumeClaimRef struct {
Expand Down Expand Up @@ -147,5 +148,6 @@ func (p *PersistentVolume) Relations() []database.Relation {
database.HasMany(p.ResourceAnnotations, database.WithForeignKey("resource_uuid")),
database.HasMany(p.Annotations, database.WithoutCascadeDelete()),
database.HasMany(p.PersistentVolumeAnnotations, fk),
database.HasMany(p.Favorites, database.WithForeignKey("resource_uuid")),
}
}
2 changes: 2 additions & 0 deletions pkg/schema/v1/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ type Pod struct {
ResourceAnnotations []ResourceAnnotation `db:"-"`
Pvcs []PodPvc `db:"-"`
Volumes []PodVolume `db:"-"`
Favorites []Favorite `db:"-"`
factory *PodFactory
}

Expand Down Expand Up @@ -459,6 +460,7 @@ func (p *Pod) Relations() []database.Relation {
database.HasMany(p.PodAnnotations, fk),
database.HasMany(p.Pvcs, fk),
database.HasMany(p.Volumes, fk),
database.HasMany(p.Favorites, database.WithForeignKey("resource_uuid")),
}
}

Expand Down
2 changes: 2 additions & 0 deletions pkg/schema/v1/pvc.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ type Pvc struct {
Annotations []Annotation `db:"-"`
PvcAnnotations []PvcAnnotation `db:"-"`
ResourceAnnotations []ResourceAnnotation `db:"-"`
Favorites []Favorite `db:"-"`
}

type PvcCondition struct {
Expand Down Expand Up @@ -172,5 +173,6 @@ func (p *Pvc) Relations() []database.Relation {
database.HasMany(p.ResourceAnnotations, database.WithForeignKey("resource_uuid")),
database.HasMany(p.Annotations, database.WithoutCascadeDelete()),
database.HasMany(p.PvcAnnotations, fk),
database.HasMany(p.Favorites, database.WithForeignKey("resource_uuid")),
}
}
2 changes: 2 additions & 0 deletions pkg/schema/v1/replica_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type ReplicaSet struct {
Annotations []Annotation `db:"-"`
ReplicaSetAnnotations []ReplicaSetAnnotation `db:"-"`
ResourceAnnotations []ResourceAnnotation `db:"-"`
Favorites []Favorite `db:"-"`
}

type ReplicaSetCondition struct {
Expand Down Expand Up @@ -217,5 +218,6 @@ func (r *ReplicaSet) Relations() []database.Relation {
database.HasMany(r.ResourceAnnotations, database.WithForeignKey("resource_uuid")),
database.HasMany(r.Annotations, database.WithoutCascadeDelete()),
database.HasMany(r.ReplicaSetAnnotations, fk),
database.HasMany(r.Favorites, database.WithForeignKey("resource_uuid")),
}
}
2 changes: 2 additions & 0 deletions pkg/schema/v1/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ type Service struct {
ServiceAnnotations []ServiceAnnotation `db:"-"`
ResourceAnnotations []ResourceAnnotation `db:"-"`
ServicePods []ServicePod `db:"-"`
Favorites []Favorite `db:"-"`
factory *ServiceFactory
}

Expand Down Expand Up @@ -257,5 +258,6 @@ func (s *Service) Relations() []database.Relation {
database.HasMany(s.ServiceAnnotations, fk),
database.HasMany(s.ResourceAnnotations, fk),
database.HasMany(s.ServicePods, fk),
database.HasMany(s.Favorites, database.WithForeignKey("resource_uuid")),
}
}
2 changes: 2 additions & 0 deletions pkg/schema/v1/stateful_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ type StatefulSet struct {
Annotations []Annotation `db:"-"`
StatefulSetAnnotations []StatefulSetAnnotation `db:"-"`
ResourceAnnotations []ResourceAnnotation `db:"-"`
Favorites []Favorite `db:"-"`
}

type StatefulSetCondition struct {
Expand Down Expand Up @@ -234,5 +235,6 @@ func (s *StatefulSet) Relations() []database.Relation {
database.HasMany(s.ResourceAnnotations, database.WithForeignKey("resource_uuid")),
database.HasMany(s.Annotations, database.WithoutCascadeDelete()),
database.HasMany(s.StatefulSetAnnotations, fk),
database.HasMany(s.Favorites, database.WithForeignKey("resource_uuid")),
}
}
8 changes: 8 additions & 0 deletions schema/mysql/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1003,6 +1003,14 @@ CREATE TABLE stateful_set_owner (
PRIMARY KEY (stateful_set_uuid, owner_uuid)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;

CREATE TABLE favorite (
resource_uuid binary(16) NOT NULL,
kind varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
username varchar(254) COLLATE utf8mb4_unicode_ci NOT NULL,
PRIMARY KEY (resource_uuid, username),
INDEX (kind, username)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also always add a name for the index. Please see the Icinga DB schema for examples.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would also flip the index as we could add an "All My Favorites" view .

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And I would add an order/priority column. We could then also add a feature to change the display order of the favorites.

) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;

CREATE TABLE kubernetes_instance (
uuid binary(16) NOT NULL,
cluster_uuid binary(16) NOT NULL,
Expand Down
Loading