-
Notifications
You must be signed in to change notification settings - Fork 400
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from pb82/plugins
Plugins
- Loading branch information
Showing
24 changed files
with
1,735 additions
and
77 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,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" |
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,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 | ||
} | ||
} |
Oops, something went wrong.