-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement
contracts.Entity
interface for schemav1.Types
- Loading branch information
Showing
15 changed files
with
589 additions
and
379 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package v1 | ||
|
||
import ( | ||
"database/sql" | ||
"github.com/icinga/icinga-kubernetes/pkg/contracts" | ||
"github.com/icinga/icinga-kubernetes/pkg/database" | ||
"github.com/icinga/icinga-kubernetes/pkg/types" | ||
) | ||
|
||
type Container struct { | ||
PodMeta | ||
Name string | ||
Image string | ||
CpuLimits int64 | ||
CpuRequests int64 | ||
MemoryLimits int64 | ||
MemoryRequests int64 | ||
State sql.NullString | ||
StateDetails string | ||
Ready types.Bool | ||
Started types.Bool | ||
RestartCount int32 | ||
Devices []*ContainerDevice `db:"-"` | ||
Mounts []*ContainerMount `db:"-"` | ||
} | ||
|
||
func (c *Container) Relations() []database.Relation { | ||
fk := database.WithForeignKey("container_id") | ||
|
||
return []database.Relation{ | ||
database.HasMany(c.Devices, fk), | ||
database.HasMany(c.Mounts, fk), | ||
} | ||
} | ||
|
||
type ContainerMeta struct { | ||
contracts.Meta | ||
ContainerId types.Binary | ||
} | ||
|
||
func (cm *ContainerMeta) Fingerprint() contracts.FingerPrinter { | ||
return cm | ||
} | ||
|
||
func (cm *ContainerMeta) ParentID() types.Binary { | ||
return cm.ContainerId | ||
} | ||
|
||
type ContainerDevice struct { | ||
ContainerMeta | ||
Name string | ||
Path string | ||
} | ||
|
||
type ContainerMount struct { | ||
ContainerMeta | ||
VolumeName string | ||
Path string | ||
SubPath string | ||
ReadOnly types.Bool | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,78 @@ | ||
package v1 | ||
|
||
import ( | ||
"github.com/icinga/icinga-kubernetes/pkg/contracts" | ||
"github.com/icinga/icinga-kubernetes/pkg/types" | ||
kmetav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
ktypes "k8s.io/apimachinery/pkg/types" | ||
) | ||
|
||
type Resource interface { | ||
kmetav1.Object | ||
Obtain(k8s kmetav1.Object) | ||
} | ||
|
||
type Meta struct { | ||
type ResourceMeta struct { | ||
contracts.Meta | ||
Uid ktypes.UID | ||
Namespace string | ||
Name string | ||
ResourceVersion string | ||
Created types.UnixMilli | ||
} | ||
|
||
func (m *Meta) ObtainMeta(k8s kmetav1.Object) { | ||
func (m *ResourceMeta) Fingerprint() contracts.FingerPrinter { | ||
return m | ||
} | ||
|
||
func (m *ResourceMeta) ObtainMeta(k8s kmetav1.Object) { | ||
m.Uid = k8s.GetUID() | ||
m.Namespace = k8s.GetNamespace() | ||
m.Name = k8s.GetName() | ||
m.ResourceVersion = k8s.GetResourceVersion() | ||
m.Created = types.UnixMilli(k8s.GetCreationTimestamp().Time) | ||
} | ||
|
||
func (m *Meta) GetNamespace() string { return m.Namespace } | ||
func (m *Meta) SetNamespace(string) { panic("Not expected to be called") } | ||
func (m *Meta) GetName() string { return m.Name } | ||
func (m *Meta) SetName(string) { panic("Not expected to be called") } | ||
func (m *Meta) GetGenerateName() string { panic("Not expected to be called") } | ||
func (m *Meta) SetGenerateName(string) { panic("Not expected to be called") } | ||
func (m *Meta) GetUID() ktypes.UID { return m.Uid } | ||
func (m *Meta) SetUID(ktypes.UID) { panic("Not expected to be called") } | ||
func (m *Meta) GetResourceVersion() string { return m.ResourceVersion } | ||
func (m *Meta) SetResourceVersion(string) { panic("Not expected to be called") } | ||
func (m *Meta) GetGeneration() int64 { panic("Not expected to be called") } | ||
func (m *Meta) SetGeneration(int64) { panic("Not expected to be called") } | ||
func (m *Meta) GetSelfLink() string { panic("Not expected to be called") } | ||
func (m *Meta) SetSelfLink(string) { panic("Not expected to be called") } | ||
func (m *Meta) GetCreationTimestamp() kmetav1.Time { return kmetav1.NewTime(m.Created.Time()) } | ||
func (m *Meta) SetCreationTimestamp(kmetav1.Time) { panic("Not expected to be called") } | ||
func (m *Meta) GetDeletionTimestamp() *kmetav1.Time { panic("Not expected to be called") } | ||
func (m *Meta) SetDeletionTimestamp(*kmetav1.Time) { panic("Not expected to be called") } | ||
func (m *Meta) GetDeletionGracePeriodSeconds() *int64 { panic("Not expected to be called") } | ||
func (m *Meta) SetDeletionGracePeriodSeconds(*int64) { panic("Not expected to be called") } | ||
func (m *Meta) GetLabels() map[string]string { panic("Not expected to be called") } | ||
func (m *Meta) SetLabels(map[string]string) { panic("Not expected to be called") } | ||
func (m *Meta) GetAnnotations() map[string]string { panic("Not expected to be called") } | ||
func (m *Meta) SetAnnotations(_ map[string]string) { panic("Not expected to be called") } | ||
func (m *Meta) GetFinalizers() []string { panic("Not expected to be called") } | ||
func (m *Meta) SetFinalizers([]string) { panic("Not expected to be called") } | ||
func (m *Meta) GetOwnerReferences() []kmetav1.OwnerReference { panic("Not expected to be called") } | ||
func (m *Meta) SetOwnerReferences([]kmetav1.OwnerReference) { panic("Not expected to be called") } | ||
func (m *Meta) GetManagedFields() []kmetav1.ManagedFieldsEntry { panic("Not expected to be called") } | ||
func (m *Meta) SetManagedFields([]kmetav1.ManagedFieldsEntry) { panic("Not expected to be called") } | ||
func (m *ResourceMeta) GetNamespace() string { return m.Namespace } | ||
func (m *ResourceMeta) SetNamespace(string) { panic("Not expected to be called") } | ||
func (m *ResourceMeta) GetName() string { return m.Name } | ||
func (m *ResourceMeta) SetName(string) { panic("Not expected to be called") } | ||
func (m *ResourceMeta) GetGenerateName() string { panic("Not expected to be called") } | ||
func (m *ResourceMeta) SetGenerateName(string) { panic("Not expected to be called") } | ||
func (m *ResourceMeta) GetUID() ktypes.UID { return m.Uid } | ||
func (m *ResourceMeta) SetUID(ktypes.UID) { panic("Not expected to be called") } | ||
func (m *ResourceMeta) GetResourceVersion() string { return m.ResourceVersion } | ||
func (m *ResourceMeta) SetResourceVersion(string) { panic("Not expected to be called") } | ||
func (m *ResourceMeta) GetGeneration() int64 { panic("Not expected to be called") } | ||
func (m *ResourceMeta) SetGeneration(int64) { panic("Not expected to be called") } | ||
func (m *ResourceMeta) GetSelfLink() string { panic("Not expected to be called") } | ||
func (m *ResourceMeta) SetSelfLink(string) { panic("Not expected to be called") } | ||
func (m *ResourceMeta) GetCreationTimestamp() kmetav1.Time { return kmetav1.NewTime(m.Created.Time()) } | ||
func (m *ResourceMeta) SetCreationTimestamp(kmetav1.Time) { panic("Not expected to be called") } | ||
func (m *ResourceMeta) GetDeletionTimestamp() *kmetav1.Time { panic("Not expected to be called") } | ||
func (m *ResourceMeta) SetDeletionTimestamp(*kmetav1.Time) { panic("Not expected to be called") } | ||
func (m *ResourceMeta) GetDeletionGracePeriodSeconds() *int64 { panic("Not expected to be called") } | ||
func (m *ResourceMeta) SetDeletionGracePeriodSeconds(*int64) { panic("Not expected to be called") } | ||
func (m *ResourceMeta) GetLabels() map[string]string { panic("Not expected to be called") } | ||
func (m *ResourceMeta) SetLabels(map[string]string) { panic("Not expected to be called") } | ||
func (m *ResourceMeta) GetAnnotations() map[string]string { panic("Not expected to be called") } | ||
func (m *ResourceMeta) SetAnnotations(_ map[string]string) { panic("Not expected to be called") } | ||
func (m *ResourceMeta) GetFinalizers() []string { panic("Not expected to be called") } | ||
func (m *ResourceMeta) SetFinalizers([]string) { panic("Not expected to be called") } | ||
func (m *ResourceMeta) GetOwnerReferences() []kmetav1.OwnerReference { | ||
panic("Not expected to be called") | ||
} | ||
func (m *ResourceMeta) SetOwnerReferences([]kmetav1.OwnerReference) { | ||
panic("Not expected to be called") | ||
} | ||
func (m *ResourceMeta) GetManagedFields() []kmetav1.ManagedFieldsEntry { | ||
panic("Not expected to be called") | ||
} | ||
func (m *ResourceMeta) SetManagedFields([]kmetav1.ManagedFieldsEntry) { | ||
panic("Not expected to be called") | ||
} | ||
|
||
// Assert interface compliance. | ||
var ( | ||
_ kmetav1.Object = (*Meta)(nil) | ||
_ kmetav1.Object = (*ResourceMeta)(nil) | ||
_ contracts.FingerPrinter = (*ResourceMeta)(nil) | ||
_ contracts.Checksumer = (*ResourceMeta)(nil) | ||
_ contracts.IDer = (*ResourceMeta)(nil) | ||
_ contracts.ParentIDer = (*ResourceMeta)(nil) | ||
_ contracts.Entity = (*ResourceMeta)(nil) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.