You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by as...@apache.org on 2020/01/15 07:41:38 UTC
[camel-k] branch master updated (cc1d24b -> 9b54ffb)
This is an automated email from the ASF dual-hosted git repository.
astefanutti pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/camel-k.git.
from cc1d24b fix(jolokia): Order consistently Jolokia agent options when encoded as environment variable
new ed143d1 chore(jolokia): Declare client certificate Jolokia trait option as an array
new 9b54ffb chore(jolokia): Factorize map keys sorting util method
The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
pkg/trait/jolokia.go | 47 +++++++++++++++++++++++++++--------------------
pkg/util/digest/digest.go | 25 ++++++-------------------
pkg/util/util.go | 12 ++++++++++++
3 files changed, 45 insertions(+), 39 deletions(-)
[camel-k] 01/02: chore(jolokia): Declare client certificate Jolokia
trait option as an array
Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
astefanutti pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit ed143d184a59a6cf14b0854c96f893c7e45261b9
Author: Antonin Stefanutti <an...@stefanutti.fr>
AuthorDate: Tue Jan 14 17:54:31 2020 +0100
chore(jolokia): Declare client certificate Jolokia trait option as an array
---
pkg/trait/jolokia.go | 37 ++++++++++++++++++++++++++-----------
1 file changed, 26 insertions(+), 11 deletions(-)
diff --git a/pkg/trait/jolokia.go b/pkg/trait/jolokia.go
index 1eb22cb..e7dfa1f 100644
--- a/pkg/trait/jolokia.go
+++ b/pkg/trait/jolokia.go
@@ -44,7 +44,7 @@ type jolokiaTrait struct {
// The principal which must be given in a client certificate to allow access to the Jolokia endpoint,
// applicable when `protocol` is `https` and `use-ssl-client-authentication` is `true`
// (default `clientPrincipal=cn=system:master-proxy` for OpenShift).
- ClientPrincipal *string `property:"client-principal"`
+ ClientPrincipal []string `property:"client-principal"`
// Listen for multicast requests (default `false`)
DiscoveryEnabled *bool `property:"discovery-enabled"`
// Mandate the client certificate contains a client flag in the extended key usage section,
@@ -90,6 +90,11 @@ func (t *jolokiaTrait) Configure(e *Environment) (bool, error) {
return false, err
}
+ if len(t.ClientPrincipal) == 1 {
+ // Work-around the lack of proper support for multi-valued trait options from the CLI
+ t.ClientPrincipal = strings.Split(t.ClientPrincipal[0], ",")
+ }
+
setDefaultJolokiaOption(options, &t.Host, "host", "*")
setDefaultJolokiaOption(options, &t.DiscoveryEnabled, "discoveryEnabled", false)
@@ -99,6 +104,13 @@ func (t *jolokiaTrait) Configure(e *Environment) (bool, error) {
setDefaultJolokiaOption(options, &t.CaCert, "caCert", "/var/run/secrets/kubernetes.io/serviceaccount/service-ca.crt")
setDefaultJolokiaOption(options, &t.ExtendedClientCheck, "extendedClientCheck", true)
setDefaultJolokiaOption(options, &t.UseSslClientAuthentication, "useSslClientAuthentication", true)
+ setDefaultJolokiaOption(options, &t.ClientPrincipal, "clientPrincipal", []string{
+ // Master API proxy for OpenShift 3
+ "cn=system:master-proxy",
+ // Default Hawtio and Fuse consoles for OpenShift 4
+ "cn=hawtio-online.hawtio.svc",
+ "cn=fuse-console.fuse.svc",
+ })
}
return e.IntegrationInPhase(
@@ -153,16 +165,7 @@ func (t *jolokiaTrait) Apply(e *Environment) (err error) {
// Then add explicitly set trait configuration properties
addToJolokiaOptions(options, "caCert", t.CaCert)
- if options["clientPrincipal"] == "" && t.ClientPrincipal == nil && e.DetermineProfile() == v1.TraitProfileOpenShift {
- // TODO: simplify when trait array options are supported
- // Master API proxy for OpenShift 3
- addToJolokiaOptions(options, "clientPrincipal.1", "cn=system:master-proxy")
- // Default Hawtio and Fuse consoles for OpenShift 4
- addToJolokiaOptions(options, "clientPrincipal.2", "cn=hawtio-online.hawtio.svc")
- addToJolokiaOptions(options, "clientPrincipal.3", "cn=fuse-console.fuse.svc")
- } else {
- addToJolokiaOptions(options, "clientPrincipal", t.ClientPrincipal)
- }
+ addToJolokiaOptions(options, "clientPrincipal", t.ClientPrincipal)
addToJolokiaOptions(options, "discoveryEnabled", t.DiscoveryEnabled)
addToJolokiaOptions(options, "extendedClientCheck", t.ExtendedClientCheck)
addToJolokiaOptions(options, "host", t.Host)
@@ -227,6 +230,10 @@ func setDefaultJolokiaOption(options map[string]string, option interface{}, key
v := value.(string)
*o = &v
}
+ case *[]string:
+ if len(*o) == 0 {
+ *o = value.([]string)
+ }
}
}
@@ -250,5 +257,13 @@ func addToJolokiaOptions(options map[string]string, key string, value interface{
if v != "" {
options[key] = v
}
+ case []string:
+ if len(v) == 1 {
+ options[key] = v[0]
+ } else {
+ for i, vi := range v {
+ options[key+"."+strconv.Itoa(i+1)] = vi
+ }
+ }
}
}
[camel-k] 02/02: chore(jolokia): Factorize map keys sorting util
method
Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
astefanutti pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit 9b54ffb363553168b4eabcdcebe0efa7474dbefa
Author: Antonin Stefanutti <an...@stefanutti.fr>
AuthorDate: Tue Jan 14 18:12:34 2020 +0100
chore(jolokia): Factorize map keys sorting util method
---
pkg/trait/jolokia.go | 10 +---------
pkg/util/digest/digest.go | 25 ++++++-------------------
pkg/util/util.go | 12 ++++++++++++
3 files changed, 19 insertions(+), 28 deletions(-)
diff --git a/pkg/trait/jolokia.go b/pkg/trait/jolokia.go
index e7dfa1f..5022d90 100644
--- a/pkg/trait/jolokia.go
+++ b/pkg/trait/jolokia.go
@@ -19,7 +19,6 @@ package trait
import (
"fmt"
- "sort"
"strconv"
"strings"
@@ -178,15 +177,8 @@ func (t *jolokiaTrait) Apply(e *Environment) (err error) {
// Lastly set the AB_JOLOKIA_OPTS environment variable from the fabric8/s2i-java base image
// Options must be sorted so that the environment variable value is consistent over iterations,
// otherwise the value changes which results in triggering a new deployment.
- optionKeys := make([]string, len(options))
- i := 0
- for k := range options {
- optionKeys[i] = k
- i++
- }
- sort.Strings(optionKeys)
optionValues := make([]string, len(options))
- for i, k := range optionKeys {
+ for i, k := range util.SortedStringMapKeys(options) {
optionValues[i] = k + "=" + options[k]
}
envvar.SetVal(&container.Env, "AB_JOLOKIA_OPTS", strings.Join(optionValues, ","))
diff --git a/pkg/util/digest/digest.go b/pkg/util/digest/digest.go
index ea5afa7..62ec3fa 100644
--- a/pkg/util/digest/digest.go
+++ b/pkg/util/digest/digest.go
@@ -20,11 +20,10 @@ package digest
import (
"crypto/sha256"
"encoding/base64"
- "math/rand"
"sort"
- "strconv"
v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
+ "github.com/apache/camel-k/pkg/util"
"github.com/apache/camel-k/pkg/util/defaults"
)
@@ -81,7 +80,7 @@ func ComputeForIntegration(integration *v1.Integration) (string, error) {
return "", err
}
spec := integration.Spec.Traits[name]
- for _, prop := range sortedStringMapKeys(spec.Configuration) {
+ for _, prop := range util.SortedStringMapKeys(spec.Configuration) {
val := spec.Configuration[prop]
if _, err := hash.Write([]byte(prop + "=" + val + ",")); err != nil {
return "", err
@@ -122,24 +121,12 @@ func ComputeForIntegrationKit(kit *v1.IntegrationKit) (string, error) {
return digest, nil
}
-// Random --
-func Random() string {
- return "v" + strconv.FormatInt(rand.Int63(), 10)
-}
-
-func sortedStringMapKeys(m map[string]string) []string {
- res := make([]string, 0, len(m))
- for k := range m {
- res = append(res, k)
- }
- sort.Strings(res)
- return res
-}
-
func sortedTraitSpecMapKeys(m map[string]v1.TraitSpec) []string {
- res := make([]string, 0, len(m))
+ res := make([]string, len(m))
+ i := 0
for k := range m {
- res = append(res, k)
+ res[i] = k
+ i++
}
sort.Strings(res)
return res
diff --git a/pkg/util/util.go b/pkg/util/util.go
index 542e7cf..c6004fd 100644
--- a/pkg/util/util.go
+++ b/pkg/util/util.go
@@ -24,6 +24,7 @@ import (
"os/signal"
"path"
"regexp"
+ "sort"
"syscall"
"github.com/scylladb/go-set/strset"
@@ -196,3 +197,14 @@ func FileExists(name string) (bool, error) {
type BytesMarshaller interface {
MarshalBytes() ([]byte, error)
}
+
+func SortedStringMapKeys(m map[string]string) []string {
+ res := make([]string, len(m))
+ i := 0
+ for k := range m {
+ res[i] = k
+ i++
+ }
+ sort.Strings(res)
+ return res
+}