-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pkg/cmd/render: add support for s390 and s390x arch
Signed-off-by: Sam Batschelet <sbatsche@redhat.com>
- Loading branch information
Showing
5 changed files
with
167 additions
and
36 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package render | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/openshift/cluster-etcd-operator/pkg/etcdenvvar" | ||
) | ||
|
||
var envVarFns = []envVarFunc{ | ||
getFixedEtcdEnvVars, | ||
getHeartbeatInterval, | ||
getElectionTimeout, | ||
getUnsupportedArch, | ||
getEtcdName, | ||
} | ||
|
||
type envVarFunc func(platform, arch string) (map[string]string, error) | ||
|
||
func getEtcdEnv(platform, arch string) (map[string]string, error) { | ||
ret := map[string]string{} | ||
for _, envVarFn := range envVarFns { | ||
newEnvVars, err := envVarFn(platform, arch) | ||
if err != nil { | ||
return nil, err | ||
} | ||
if newEnvVars == nil { | ||
continue | ||
} | ||
for k, v := range newEnvVars { | ||
if currV, ok := ret[k]; ok { | ||
return nil, fmt.Errorf("key %q already set to %q", k, currV) | ||
} | ||
ret[k] = v | ||
} | ||
} | ||
return ret, nil | ||
} | ||
|
||
func getFixedEtcdEnvVars(platform, arch string) (map[string]string, error) { | ||
return etcdenvvar.FixedEtcdEnvVars, nil | ||
} | ||
|
||
func getEtcdName(platform, arch string) (map[string]string, error) { | ||
return map[string]string{ | ||
"ETCD_NAME": "etcd-bootstrap", | ||
}, nil | ||
} | ||
|
||
func getHeartbeatInterval(platform, arch string) (map[string]string, error) { | ||
var heartbeat string | ||
|
||
switch platform { | ||
case "Azure": | ||
heartbeat = "500" | ||
default: | ||
heartbeat = "100" | ||
} | ||
|
||
return map[string]string{ | ||
"ETCD_HEARTBEAT_INTERVAL": heartbeat, | ||
}, nil | ||
} | ||
|
||
func getElectionTimeout(platform, arch string) (map[string]string, error) { | ||
var timeout string | ||
|
||
switch platform { | ||
case "Azure": | ||
timeout = "2500" | ||
default: | ||
timeout = "1000" | ||
} | ||
|
||
return map[string]string{ | ||
"ETCD_ELECTION_TIMEOUT": timeout, | ||
}, nil | ||
|
||
} | ||
|
||
func getUnsupportedArch(platform, arch string) (map[string]string, error) { | ||
if !strings.HasPrefix(arch, "s390") { | ||
// dont set unless it is defined. | ||
return nil, nil | ||
} | ||
return map[string]string{ | ||
"ETCD_UNSUPPORTED_ARCH": arch, | ||
}, 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,21 @@ | ||
package render | ||
|
||
import "testing" | ||
|
||
func TestEtcdEnv(t *testing.T) { | ||
for _, test := range []struct { | ||
platform, arch, wantKey, wantValue string | ||
}{ | ||
{"AWS", "amd64", "ETCD_HEARTBEAT_INTERVAL", "100"}, | ||
{"AWS", "amd64", "ETCD_ELECTION_TIMEOUT", "1000"}, | ||
{"Azure", "ppc64le", "ETCD_HEARTBEAT_INTERVAL", "500"}, | ||
{"Azure", "amd64", "ETCD_ELECTION_TIMEOUT", "2500"}, | ||
{"None", "ppc64le", "ETCD_HEARTBEAT_INTERVAL", "100"}, | ||
{"Azure", "s390x", "ETCD_UNSUPPORTED_ARCH", "s390x"}, | ||
} { | ||
env, _ := getEtcdEnv(test.platform, test.arch) | ||
if env[test.wantKey] != test.wantValue { | ||
t.Errorf("getEtcdEnv(%q, %q) = want %q = %q got %q = %q", test.platform, test.arch, test.wantKey, test.wantValue, test.wantKey, env[test.wantKey]) | ||
} | ||
} | ||
} |
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