Use unified type for the namespaced object names

This commit is contained in:
Murat Kabilov
2017-05-12 11:41:34 +02:00
parent 79fdba4ac7
commit 08c0e3b6dd
10 changed files with 69 additions and 85 deletions
+10 -7
View File
@@ -6,6 +6,7 @@ import (
"strings"
"time"
"github.bus.zalan.do/acid/postgres-operator/pkg/spec"
"github.com/kelseyhightower/envconfig"
)
@@ -24,13 +25,13 @@ type Resources struct {
}
type Auth struct {
PamRoleName string `split_words:"true" default:"zalandos"`
PamConfiguration string `split_words:"true" default:"https://info.example.com/oauth2/tokeninfo?access_token= uid realm=/employees"`
TeamsAPIUrl string `envconfig:"teams_api_url" default:"https://teams.example.com/api/"`
OAuthTokenSecretName string `envconfig:"oauth_token_secret_name" default:"postgresql-operator"`
InfrastructureRolesSecretName string `split_words:"true"`
SuperUsername string `split_words:"true" default:"postgres"`
ReplicationUsername string `split_words:"true" default:"replication"`
PamRoleName string `split_words:"true" default:"zalandos"`
PamConfiguration string `split_words:"true" default:"https://info.example.com/oauth2/tokeninfo?access_token= uid realm=/employees"`
TeamsAPIUrl string `envconfig:"teams_api_url" default:"https://teams.example.com/api/"`
OAuthTokenSecretName spec.NamespacedName `envconfig:"oauth_token_secret_name" default:"postgresql-operator"`
InfrastructureRolesSecretName spec.NamespacedName `split_words:"true"`
SuperUsername string `split_words:"true" default:"postgres"`
ReplicationUsername string `split_words:"true" default:"replication"`
}
type Config struct {
@@ -49,6 +50,8 @@ type Config struct {
}
func LoadFromEnv() *Config {
//TODO: maybe we should use ConfigMaps( https://kubernetes.io/docs/tasks/configure-pod-container/configmap/ ) instead?
var cfg Config
err := envconfig.Process("PGOP", &cfg)
if err != nil {
+5 -8
View File
@@ -11,7 +11,6 @@ import (
"github.bus.zalan.do/acid/postgres-operator/pkg/spec"
"k8s.io/client-go/pkg/api/v1"
"k8s.io/client-go/pkg/types"
"strings"
)
@@ -30,24 +29,22 @@ func RandomPassword(n int) string {
return string(b)
}
func NameFromMeta(meta v1.ObjectMeta) types.NamespacedName {
obj := types.NamespacedName{
func NameFromMeta(meta v1.ObjectMeta) spec.NamespacedName {
return spec.NamespacedName{
Namespace: meta.Namespace,
Name: meta.Name,
}
return obj
}
func PodClusterName(pod *v1.Pod) spec.ClusterName {
func PodClusterName(pod *v1.Pod) spec.NamespacedName {
if name, ok := pod.Labels["spilo-cluster"]; ok {
return spec.ClusterName{
return spec.NamespacedName{
Namespace: pod.Namespace,
Name: name,
}
}
return spec.ClusterName{}
return spec.NamespacedName{}
}
func PodSpiloRole(pod *v1.Pod) string {