#1 Split plugins in two groups:required by operator and required by user

This commit is contained in:
Tomasz Sęk
2019-02-16 20:29:59 +01:00
parent dd04c0cf5b
commit 08b6dfb691
13 changed files with 349 additions and 250 deletions
+71 -57
View File
@@ -1,56 +1,72 @@
package plugins
const (
// ApacheComponentsClientPlugin is apache-httpcomponents-client-4-api Jenkins plugin with version
ApacheComponentsClientPlugin = "apache-httpcomponents-client-4-api:4.5.5-3.0"
// Jackson2ADIPlugin is jackson2-api-httpcomponents-client-4-api Jenkins plugin with version
Jackson2ADIPlugin = "jackson2-api:2.9.8"
apacheComponentsClientPlugin = "apache-httpcomponents-client-4-api:4.5.5-3.0"
jackson2ADIPlugin = "jackson2-api:2.9.8"
credentialsPlugin = "credentials:2.1.18"
cloudBeesFolderPlugin = "cloudbees-folder:6.7"
durableTaskPlugin = "durable-task:1.28"
plainCredentialsPlugin = "plain-credentials:1.5"
structsPlugin = "structs:1.17"
workflowStepAPIPlugin = "workflow-step-api:2.17"
scmAPIPlugin = "scm-api:2.3.0"
workflowAPIPlugin = "workflow-api:2.33"
workflowSupportPlugin = "workflow-support:3.0"
displayURLAPIPlugin = "display-url-api:2.3.0"
gitClientPlugin = "git-client:2.7.6"
jschPlugin = "jsch:0.1.55"
junitPlugin = "junit:1.26.1"
mailerPlugin = "mailer:1.23"
matrixProjectPlugin = "matrix-project:1.13"
scriptSecurityPlugin = "script-security:1.50"
sshCredentialsPlugin = "ssh-credentials:1.14"
workflowSCMStepPlugin = "workflow-scm-step:2.7"
)
// BasePluginsMap contains plugins to install by operator
var BasePluginsMap = map[string][]Plugin{
Must(New("kubernetes:1.13.8")).String(): {
Must(New(ApacheComponentsClientPlugin)),
Must(New("cloudbees-folder:6.7")),
Must(New("credentials:2.1.18")),
Must(New("durable-task:1.28")),
Must(New(Jackson2ADIPlugin)),
Must(New(apacheComponentsClientPlugin)),
Must(New(cloudBeesFolderPlugin)),
Must(New(credentialsPlugin)),
Must(New(durableTaskPlugin)),
Must(New(jackson2ADIPlugin)),
Must(New("kubernetes-credentials:0.4.0")),
Must(New("plain-credentials:1.5")),
Must(New("structs:1.17")),
Must(New(plainCredentialsPlugin)),
Must(New(structsPlugin)),
Must(New("variant:1.1")),
Must(New("workflow-step-api:2.17")),
Must(New(workflowStepAPIPlugin)),
},
Must(New("workflow-job:2.31")).String(): {
Must(New("scm-api:2.3.0")),
Must(New("script-security:1.50")),
Must(New("structs:1.17")),
Must(New("workflow-api:2.33")),
Must(New("workflow-step-api:2.17")),
Must(New("workflow-support:3.0")),
Must(New(scmAPIPlugin)),
Must(New(scriptSecurityPlugin)),
Must(New(structsPlugin)),
Must(New(workflowAPIPlugin)),
Must(New(workflowStepAPIPlugin)),
Must(New(workflowSupportPlugin)),
},
Must(New("workflow-aggregator:2.6")).String(): {
Must(New("ace-editor:1.1")),
Must(New(ApacheComponentsClientPlugin)),
Must(New(apacheComponentsClientPlugin)),
Must(New("authentication-tokens:1.3")),
Must(New("branch-api:2.1.2")),
Must(New("cloudbees-folder:6.7")),
Must(New(cloudBeesFolderPlugin)),
Must(New("credentials-binding:1.17")),
Must(New("credentials:2.1.18")),
Must(New("display-url-api:2.3.0")),
Must(New(credentialsPlugin)),
Must(New(displayURLAPIPlugin)),
Must(New("docker-commons:1.13")),
Must(New("docker-workflow:1.17")),
Must(New("durable-task:1.28")),
Must(New("git-client:2.7.6")),
Must(New(durableTaskPlugin)),
Must(New(gitClientPlugin)),
Must(New("git-server:1.7")),
Must(New("handlebars:1.1.1")),
Must(New(Jackson2ADIPlugin)),
Must(New(jackson2ADIPlugin)),
Must(New("jquery-detached:1.2.1")),
Must(New("jsch:0.1.55")),
Must(New("junit:1.26.1")),
Must(New(jschPlugin)),
Must(New(junitPlugin)),
Must(New("lockable-resources:2.3")),
Must(New("mailer:1.23")),
Must(New("matrix-project:1.13")),
Must(New(mailerPlugin)),
Must(New(matrixProjectPlugin)),
Must(New("momentjs:1.1.1")),
Must(New("pipeline-build-step:2.7")),
Must(New("pipeline-graph-analysis:1.9")),
@@ -64,48 +80,46 @@ var BasePluginsMap = map[string][]Plugin{
Must(New("pipeline-stage-step:2.3")),
Must(New("pipeline-stage-tags-metadata:1.3.4.1")),
Must(New("pipeline-stage-view:2.10")),
Must(New("plain-credentials:1.5")),
Must(New("scm-api:2.3.0")),
Must(New("script-security:1.50")),
Must(New("ssh-credentials:1.14")),
Must(New("structs:1.17")),
Must(New("workflow-api:2.33")),
Must(New(plainCredentialsPlugin)),
Must(New(scmAPIPlugin)),
Must(New(scriptSecurityPlugin)),
Must(New(sshCredentialsPlugin)),
Must(New(structsPlugin)),
Must(New(workflowAPIPlugin)),
Must(New("workflow-basic-steps:2.13")),
Must(New("workflow-cps-global-lib:2.12")),
Must(New("workflow-cps:2.61.1")),
Must(New("workflow-durable-task-step:2.27")),
Must(New("workflow-job:2.31")),
Must(New("workflow-multibranch:2.20")),
Must(New("workflow-scm-step:2.7")),
Must(New("workflow-step-api:2.17")),
Must(New("workflow-support:3.0")),
Must(New(workflowSCMStepPlugin)),
Must(New(workflowStepAPIPlugin)),
Must(New(workflowSupportPlugin)),
},
Must(New("git:3.9.1")).String(): {
Must(New(ApacheComponentsClientPlugin)),
Must(New("credentials:2.1.18")),
Must(New("display-url-api:2.3.0")),
Must(New("git-client:2.7.6")),
Must(New("jsch:0.1.55")),
Must(New("junit:1.26.1")),
Must(New("mailer:1.23")),
Must(New("matrix-project:1.13")),
Must(New("scm-api:2.3.0")),
Must(New("script-security:1.50")),
Must(New("ssh-credentials:1.14")),
Must(New("structs:1.17")),
Must(New("workflow-api:2.33")),
Must(New("workflow-scm-step:2.7")),
Must(New("workflow-step-api:2.17")),
Must(New(apacheComponentsClientPlugin)),
Must(New(credentialsPlugin)),
Must(New(displayURLAPIPlugin)),
Must(New(gitClientPlugin)),
Must(New(jschPlugin)),
Must(New(junitPlugin)),
Must(New(mailerPlugin)),
Must(New(matrixProjectPlugin)),
Must(New(scmAPIPlugin)),
Must(New(scriptSecurityPlugin)),
Must(New(sshCredentialsPlugin)),
Must(New(structsPlugin)),
Must(New(workflowAPIPlugin)),
Must(New(workflowSCMStepPlugin)),
Must(New(workflowStepAPIPlugin)),
},
Must(New("job-dsl:1.71")).String(): {
Must(New("script-security:1.50")),
Must(New("structs:1.17")),
Must(New(scriptSecurityPlugin)),
Must(New(structsPlugin)),
},
Must(New("jobConfigHistory:2.19")).String(): {},
Must(New("configuration-as-code:1.4")).String(): {
Must(New("configuration-as-code-support:1.4")),
},
Must(New("simple-theme-plugin:0.5.1")).String(): {},
}
// BasePlugins returns map of plugins to install by operator
+7 -11
View File
@@ -40,26 +40,22 @@ func Must(plugin *Plugin, err error) Plugin {
}
// VerifyDependencies checks if all plugins have compatible versions
func VerifyDependencies(values ...map[string][]Plugin) bool {
func VerifyDependencies(values ...map[Plugin][]Plugin) bool {
// key - plugin name, value array of versions
allPlugins := make(map[string][]Plugin)
valid := true
for _, value := range values {
for rootPluginNameAndVersion, plugins := range value {
if rootPlugin, err := New(rootPluginNameAndVersion); err != nil {
valid = false
} else {
allPlugins[rootPlugin.Name] = append(allPlugins[rootPlugin.Name], Plugin{
Name: rootPlugin.Name,
Version: rootPlugin.Version,
rootPluginNameAndVersion: rootPluginNameAndVersion})
}
for rootPlugin, plugins := range value {
allPlugins[rootPlugin.Name] = append(allPlugins[rootPlugin.Name], Plugin{
Name: rootPlugin.Name,
Version: rootPlugin.Version,
rootPluginNameAndVersion: rootPlugin.String()})
for _, plugin := range plugins {
allPlugins[plugin.Name] = append(allPlugins[plugin.Name], Plugin{
Name: plugin.Name,
Version: plugin.Version,
rootPluginNameAndVersion: rootPluginNameAndVersion})
rootPluginNameAndVersion: rootPlugin.String()})
}
}
}
+75 -77
View File
@@ -1,90 +1,88 @@
package plugins
import (
"fmt"
"github.com/jenkinsci/kubernetes-operator/pkg/log"
"testing"
"github.com/jenkinsci/kubernetes-operator/pkg/log"
"github.com/stretchr/testify/assert"
)
func TestVerifyDependencies(t *testing.T) {
data := []struct {
basePlugins map[string][]Plugin
extraPlugins map[string][]Plugin
expectedResult bool
}{
{
basePlugins: map[string][]Plugin{
"first-root-plugin:1.0.0": {
Must(New("first-plugin:0.0.1")),
},
},
expectedResult: true,
},
{
basePlugins: map[string][]Plugin{
"first-root-plugin:1.0.0": {
Must(New("first-plugin:0.0.1")),
},
"second-root-plugin:1.0.0": {
Must(New("first-plugin:0.0.1")),
},
},
expectedResult: true,
},
{
basePlugins: map[string][]Plugin{
"first-root-plugin:1.0.0": {
Must(New("first-plugin:0.0.1")),
},
},
extraPlugins: map[string][]Plugin{
"second-root-plugin:2.0.0": {
Must(New("first-plugin:0.0.1")),
},
},
expectedResult: true,
},
{
basePlugins: map[string][]Plugin{
"first-root-plugin:1.0.0": {
Must(New("first-plugin:0.0.1")),
},
"first-root-plugin:2.0.0": {
Must(New("first-plugin:0.0.2")),
},
},
expectedResult: false,
},
{
basePlugins: map[string][]Plugin{
"first-root-plugin:1.0.0": {
Must(New("first-plugin:0.0.1")),
},
},
extraPlugins: map[string][]Plugin{
"first-root-plugin:2.0.0": {
Must(New("first-plugin:0.0.2")),
},
},
expectedResult: false,
},
{
basePlugins: map[string][]Plugin{
"invalid-plugin-name": {},
},
expectedResult: false,
},
}
debug := false
log.SetupLogger(&debug)
for index, testingData := range data {
t.Run(fmt.Sprintf("Testing %d data", index), func(t *testing.T) {
result := VerifyDependencies(testingData.basePlugins, testingData.extraPlugins)
assert.Equal(t, testingData.expectedResult, result)
})
}
t.Run("happy, single root plugin with one dependent plugin", func(t *testing.T) {
basePlugins := map[Plugin][]Plugin{
Must(New("first-root-plugin:1.0.0")): {
Must(New("first-plugin:0.0.1")),
},
}
got := VerifyDependencies(basePlugins)
assert.Equal(t, true, got)
})
t.Run("happy, two root plugins with one depended plugin with the same version", func(t *testing.T) {
basePlugins := map[Plugin][]Plugin{
Must(New("first-root-plugin:1.0.0")): {
Must(New("first-plugin:0.0.1")),
},
Must(New("second-root-plugin:1.0.0")): {
Must(New("first-plugin:0.0.1")),
},
}
got := VerifyDependencies(basePlugins)
assert.Equal(t, true, got)
})
t.Run("fail, two root plugins have different versions", func(t *testing.T) {
basePlugins := map[Plugin][]Plugin{
Must(New("first-root-plugin:1.0.0")): {
Must(New("first-plugin:0.0.1")),
},
Must(New("first-root-plugin:2.0.0")): {
Must(New("first-plugin:0.0.1")),
},
}
got := VerifyDependencies(basePlugins)
assert.Equal(t, false, got)
})
t.Run("happy, no version collision with two sperate plugins lists", func(t *testing.T) {
basePlugins := map[Plugin][]Plugin{
Must(New("first-root-plugin:1.0.0")): {
Must(New("first-plugin:0.0.1")),
},
}
extraPlugins := map[Plugin][]Plugin{
Must(New("second-root-plugin:2.0.0")): {
Must(New("first-plugin:0.0.1")),
},
}
got := VerifyDependencies(basePlugins, extraPlugins)
assert.Equal(t, true, got)
})
t.Run("fail, dependent plugins have different versions", func(t *testing.T) {
basePlugins := map[Plugin][]Plugin{
Must(New("first-root-plugin:1.0.0")): {
Must(New("first-plugin:0.0.1")),
},
Must(New("first-root-plugin:2.0.0")): {
Must(New("first-plugin:0.0.2")),
},
}
got := VerifyDependencies(basePlugins)
assert.Equal(t, false, got)
})
t.Run("fail, root and dependent plugins have different versions", func(t *testing.T) {
basePlugins := map[Plugin][]Plugin{
Must(New("first-root-plugin:1.0.0")): {
Must(New("first-plugin:0.0.1")),
},
}
extraPlugins := map[Plugin][]Plugin{
Must(New("first-root-plugin:2.0.0")): {
Must(New("first-plugin:0.0.2")),
},
}
got := VerifyDependencies(basePlugins, extraPlugins)
assert.Equal(t, false, got)
})
}