-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
288 additions
and
0 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
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
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,69 @@ | ||
package common | ||
|
||
import ( | ||
"github.com/icinga/icinga-go-library/database" | ||
"github.com/icinga/icinga-go-library/types" | ||
"github.com/icinga/icinga-kubernetes/pkg/contracts" | ||
kmetav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
type IdMeta struct { | ||
Id types.Binary | ||
} | ||
|
||
func (m *IdMeta) ID() database.ID { | ||
return m.Id | ||
} | ||
|
||
func (m *IdMeta) SetID(id database.ID) { | ||
m.Id = id.(types.Binary) | ||
} | ||
|
||
type CanonicalMeta struct { | ||
CanonicalName string | ||
} | ||
|
||
func (m *CanonicalMeta) GetCanonicalName() string { | ||
return m.CanonicalName | ||
} | ||
|
||
func (m *CanonicalMeta) SetCanonicalName(canonicalName string) { | ||
m.CanonicalName = canonicalName | ||
} | ||
|
||
func NewKEnvelope(key string) contracts.KEnvelope { | ||
return &kenvelope{ | ||
IdMeta: IdMeta{types.Checksum(key)}, | ||
CanonicalMeta: CanonicalMeta{key}, | ||
} | ||
} | ||
|
||
type kenvelope struct { | ||
IdMeta | ||
CanonicalMeta | ||
} | ||
|
||
func (k *kenvelope) KUpsert(kobject kmetav1.Object) contracts.KUpsert { | ||
return &kupsert{ | ||
kenvelope: *k, | ||
kobject: kobject, | ||
} | ||
} | ||
|
||
func (k *kenvelope) KDelete() contracts.KDelete { | ||
return k | ||
} | ||
|
||
type kupsert struct { | ||
kenvelope | ||
kobject kmetav1.Object | ||
} | ||
|
||
func (k *kupsert) KObject() kmetav1.Object { | ||
return k.kobject | ||
} | ||
|
||
// Assert interface compliance. | ||
var ( | ||
_ database.IDer = (*IdMeta)(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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package contracts | ||
|
||
import ( | ||
"github.com/icinga/icinga-go-library/database" | ||
"k8s.io/apimachinery/pkg/apis/meta/v1" | ||
kmetav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
// KEnvelope carries identity information about a Kubernetes resource change to be synchronized. | ||
type KEnvelope interface { | ||
entity | ||
KUpsert(kobject kmetav1.Object) KUpsert | ||
KDelete() KDelete | ||
} | ||
|
||
// KUpsert carries identity information and the added or updated Kubernetes resource to be synchronized. | ||
type KUpsert interface { | ||
entity | ||
KObject() kmetav1.Object | ||
} | ||
|
||
// KDelete carries identity information about a deleted Kubernetes resource to be synchronized. | ||
type KDelete interface { | ||
entity | ||
} | ||
|
||
// Resource represents principal entities synchronized from Kubernetes resources to the Icinga Kubernetes database. | ||
type Resource interface { | ||
entity | ||
database.Fingerprinter | ||
v1.Object | ||
Obtain(kobject v1.Object) | ||
} | ||
|
||
type entity interface { | ||
database.IDer | ||
GetCanonicalName() string | ||
SetCanonicalName(string) | ||
} |
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,107 @@ | ||
package schema | ||
|
||
import ( | ||
"github.com/icinga/icinga-go-library/database" | ||
"github.com/icinga/icinga-go-library/types" | ||
"github.com/icinga/icinga-kubernetes/pkg/common" | ||
kmetav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
ktypes "k8s.io/apimachinery/pkg/types" | ||
) | ||
|
||
type kmetaWithoutNamespace struct { | ||
common.IdMeta | ||
common.CanonicalMeta | ||
Uid ktypes.UID | ||
Name string | ||
ResourceVersion string | ||
Created types.UnixMilli | ||
} | ||
|
||
func (m *kmetaWithoutNamespace) Fingerprint() database.Fingerprinter { | ||
return m | ||
} | ||
|
||
func (m *kmetaWithoutNamespace) Obtain(kobject kmetav1.Object) { | ||
m.Uid = kobject.GetUID() | ||
m.Name = kobject.GetName() | ||
m.ResourceVersion = kobject.GetResourceVersion() | ||
m.Created = types.UnixMilli(kobject.GetCreationTimestamp().Time) | ||
} | ||
|
||
func (m *kmetaWithoutNamespace) GetNamespace() string { return "" } | ||
func (m *kmetaWithoutNamespace) SetNamespace(string) { panic("Not expected to be called") } | ||
func (m *kmetaWithoutNamespace) GetName() string { return m.Name } | ||
func (m *kmetaWithoutNamespace) SetName(string) { panic("Not expected to be called") } | ||
func (m *kmetaWithoutNamespace) GetGenerateName() string { panic("Not expected to be called") } | ||
func (m *kmetaWithoutNamespace) SetGenerateName(string) { panic("Not expected to be called") } | ||
func (m *kmetaWithoutNamespace) GetUID() ktypes.UID { return m.Uid } | ||
func (m *kmetaWithoutNamespace) SetUID(ktypes.UID) { panic("Not expected to be called") } | ||
func (m *kmetaWithoutNamespace) GetResourceVersion() string { return m.ResourceVersion } | ||
func (m *kmetaWithoutNamespace) SetResourceVersion(string) { panic("Not expected to be called") } | ||
func (m *kmetaWithoutNamespace) GetGeneration() int64 { panic("Not expected to be called") } | ||
func (m *kmetaWithoutNamespace) SetGeneration(int64) { panic("Not expected to be called") } | ||
func (m *kmetaWithoutNamespace) GetSelfLink() string { panic("Not expected to be called") } | ||
func (m *kmetaWithoutNamespace) SetSelfLink(string) { panic("Not expected to be called") } | ||
func (m *kmetaWithoutNamespace) GetCreationTimestamp() kmetav1.Time { | ||
return kmetav1.NewTime(m.Created.Time()) | ||
} | ||
func (m *kmetaWithoutNamespace) SetCreationTimestamp(kmetav1.Time) { | ||
panic("Not expected to be called") | ||
} | ||
func (m *kmetaWithoutNamespace) GetDeletionTimestamp() *kmetav1.Time { | ||
panic("Not expected to be called") | ||
} | ||
func (m *kmetaWithoutNamespace) SetDeletionTimestamp(*kmetav1.Time) { | ||
panic("Not expected to be called") | ||
} | ||
func (m *kmetaWithoutNamespace) GetDeletionGracePeriodSeconds() *int64 { | ||
panic("Not expected to be called") | ||
} | ||
func (m *kmetaWithoutNamespace) SetDeletionGracePeriodSeconds(*int64) { | ||
panic("Not expected to be called") | ||
} | ||
func (m *kmetaWithoutNamespace) GetLabels() map[string]string { panic("Not expected to be called") } | ||
func (m *kmetaWithoutNamespace) SetLabels(map[string]string) { panic("Not expected to be called") } | ||
func (m *kmetaWithoutNamespace) GetAnnotations() map[string]string { | ||
panic("Not expected to be called") | ||
} | ||
func (m *kmetaWithoutNamespace) SetAnnotations(_ map[string]string) { | ||
panic("Not expected to be called") | ||
} | ||
func (m *kmetaWithoutNamespace) GetFinalizers() []string { panic("Not expected to be called") } | ||
func (m *kmetaWithoutNamespace) SetFinalizers([]string) { panic("Not expected to be called") } | ||
func (m *kmetaWithoutNamespace) GetOwnerReferences() []kmetav1.OwnerReference { | ||
panic("Not expected to be called") | ||
} | ||
func (m *kmetaWithoutNamespace) SetOwnerReferences([]kmetav1.OwnerReference) { | ||
panic("Not expected to be called") | ||
} | ||
func (m *kmetaWithoutNamespace) GetManagedFields() []kmetav1.ManagedFieldsEntry { | ||
panic("Not expected to be called") | ||
} | ||
func (m *kmetaWithoutNamespace) SetManagedFields([]kmetav1.ManagedFieldsEntry) { | ||
panic("Not expected to be called") | ||
} | ||
|
||
type kmetaWithNamespace struct { | ||
kmetaWithoutNamespace | ||
Namespace string | ||
} | ||
|
||
func (m *kmetaWithNamespace) GetNamespace() string { return m.Namespace } | ||
|
||
func (m *kmetaWithNamespace) Fingerprint() database.Fingerprinter { | ||
return m | ||
} | ||
|
||
func (m *kmetaWithNamespace) Obtain(kobject kmetav1.Object) { | ||
m.kmetaWithoutNamespace.Obtain(kobject) | ||
|
||
m.Namespace = kobject.GetNamespace() | ||
} | ||
|
||
// Assert interface compliance. | ||
var ( | ||
_ kmetav1.Object = (*kmetaWithoutNamespace)(nil) | ||
_ kmetav1.Object = (*kmetaWithNamespace)(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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package schema | ||
|
||
type PrometheusClusterMetric struct { | ||
kmetaWithoutNamespace | ||
Timestamp int64 | ||
Group string | ||
Name string | ||
Value float64 | ||
} | ||
|
||
type PrometheusNodeMetric struct { | ||
kmetaWithoutNamespace | ||
NodeId []byte | ||
Timestamp int64 | ||
Group string | ||
Name string | ||
Value float64 | ||
} | ||
|
||
type PrometheusPodMetric struct { | ||
kmetaWithoutNamespace | ||
PodId []byte | ||
Timestamp int64 | ||
Group string | ||
Name string | ||
Value float64 | ||
} | ||
|
||
type PrometheusContainerMetric struct { | ||
kmetaWithoutNamespace | ||
ContainerId []byte | ||
Timestamp int64 | ||
Group string | ||
Name string | ||
Value float64 | ||
} |