Skip to content

Commit

Permalink
Merge pull request #6 from pb82/plugins
Browse files Browse the repository at this point in the history
Plugins
  • Loading branch information
pb82 committed Apr 23, 2019
2 parents be29e01 + 9eb8e3d commit 47a0985
Show file tree
Hide file tree
Showing 24 changed files with 1,735 additions and 77 deletions.
45 changes: 45 additions & 0 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ required = [
# branch = "v0.2.x" #osdk_branch_annotation
version = "=v0.2.1" #osdk_version_annotation

[[constraint]]
name = "github.com/blang/semver"
version = "v3.6.1"

[prune]
go-tests = true
non-go = true
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
ORG=integreatly
ORG=integr8ly
NAMESPACE=application-monitoring
PROJECT=grafana-operator
REG=quay.io
SHELL=/bin/bash
TAG=0.0.1
TAG=latest
PKG=github.com/integr8ly/grafana-operator
TEST_DIRS?=$(shell sh -c "find $(TOP_SRC_DIRS) -name \\*_test.go -exec dirname {} \\; | sort | uniq")
TEST_POD_NAME=grafana-operator-test
Expand Down
21 changes: 21 additions & 0 deletions deploy/crds/GrafanaDashboard.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,24 @@ spec:
singular: grafanadashboard
scope: Namespaced
version: v1alpha1
validation:
openAPIV3Schema:
properties:
status:
properties:
messages:
type: array
items:
description: Dashboard Status Message
type: object
spec:
properties:
name:
type: string
json:
type: string
plugins:
type: array
items:
description: Grafana Plugin Object
type: object
11 changes: 8 additions & 3 deletions deploy/examples/GrafanaDashboard.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
apiVersion: integreatly.org/v1alpha1
kind: GrafanaDashboard
metadata:
name: example-grafanadashboard
name: example
spec:
# Add fields here
size: 3
name: dashboard.json
json: "{}"
plugins:
- name: "grafana-piechart-panel"
version: "1.3.6"
- name: "grafana-clock-panel"
version: "1.0.2"
10 changes: 9 additions & 1 deletion pkg/apis/integreatly/v1alpha1/grafana_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,15 @@ type GrafanaSpec struct {
type GrafanaStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "operator-sdk generate k8s" to regenerate code after modifying this file
Phase int `json:"phase"`
Phase int `json:"phase"`
InstalledPlugins PluginList `json:"installedPlugins"`
}

// GrafanaPlugin contains information about a single plugin
type GrafanaPlugin struct {
Name string `json:"name"`
Version string `json:"version"`
Origin *GrafanaDashboard `json:"-"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
Expand Down
14 changes: 9 additions & 5 deletions pkg/apis/integreatly/v1alpha1/grafanadashboard_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@ import (
type GrafanaDashboardSpec struct {
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
// Important: Run "operator-sdk generate k8s" to regenerate code after modifying this file
Json string `json:"json"`
Name string `json:"name"`
Json string `json:"json"`
Name string `json:"name"`
Plugins PluginList `json:"plugins"`
}

// GrafanaDashboardStatus defines the observed state of GrafanaDashboard
type GrafanaDashboardStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "operator-sdk generate k8s" to regenerate code after modifying this file
Created bool `json: "created"`
Messages []GrafanaDashboardStatusMessage `json:"messages"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
Expand All @@ -43,6 +42,11 @@ type GrafanaDashboardList struct {
Items []GrafanaDashboard `json:"items"`
}

type GrafanaDashboardStatusMessage struct {
Message string `json:"message"`
Timestamp string `json:"timestamp"`
}

func init() {
SchemeBuilder.Register(&GrafanaDashboard{}, &GrafanaDashboardList{})
}
79 changes: 79 additions & 0 deletions pkg/apis/integreatly/v1alpha1/pluginsList.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package v1alpha1

import (
"github.com/blang/semver"
)

type PluginList []GrafanaPlugin

// Returns true if the list contains the same plugin in the exact or a different version
func (l PluginList) HasSomeVersionOf(plugin *GrafanaPlugin) bool {
for _, listedPlugin := range l {
if listedPlugin.Name == plugin.Name {
return true
}
}
return false
}

// Get the plugin from the list regardless of the version
func (l PluginList) GetInstalledVersionOf(plugin *GrafanaPlugin) *GrafanaPlugin {
for _, listedPlugin := range l {
if listedPlugin.Name == plugin.Name {
return &listedPlugin
}
}
return nil
}

// Returns true if the list contains the same plugin in the same version
func (l PluginList) HasExactVersionOf(plugin *GrafanaPlugin) bool {
for _, listedPlugin := range l {
if listedPlugin.Name == plugin.Name && listedPlugin.Version == plugin.Version {
return true
}
}
return false
}

// Returns true if the list contains the same plugin but in a newer version
func (l PluginList) HasNewerVersionOf(plugin *GrafanaPlugin) (bool, error) {
for _, listedPlugin := range l {
if listedPlugin.Name != plugin.Name {
continue
}

listedVersion, err := semver.Make(listedPlugin.Version)
if err != nil {
return false, err
}

requestedVersion, err := semver.Make(plugin.Version)
if err != nil {
return false, err
}

if listedVersion.Compare(requestedVersion) == 1 {
return true, nil
}
}
return false, nil
}

// Returns the number of different versions of a given plugin in the list
func (l PluginList) VersionsOf(plugin *GrafanaPlugin) int {
i := 0
for _, listedPlugin := range l {
if listedPlugin.Name == plugin.Name {
i = i + 1
}
}
return i
}

// Set the originating dashboard for every plugin in the list
func (l PluginList) SetOrigin(dashboard *GrafanaDashboard) {
for i := range l {
l[i].Origin = dashboard
}
}
Loading

0 comments on commit 47a0985

Please sign in to comment.