mirror of
https://github.com/zalando/postgres-operator.git
synced 2026-10-07 00:51:45 +02:00
WIP: first commit
This commit is contained in:
committed by
Oleksii Kliukin
parent
9cb48e0889
commit
5a1b944fed
@@ -174,8 +174,21 @@ func (c *Controller) initController() {
|
||||
c.logger.Logger.Level = logrus.DebugLevel
|
||||
}
|
||||
|
||||
if err := c.createCRD(); err != nil {
|
||||
c.logger.Fatalf("could not register CustomResourceDefinition: %v", err)
|
||||
|
||||
if err := c.createPostgresCRD(); err != nil {
|
||||
c.logger.Fatalf("could not register Postgres CustomResourceDefinition: %v", err)
|
||||
}
|
||||
|
||||
if err := c.createOperatorCRD(); err != nil {
|
||||
c.logger.Fatalf("could not register Operator Configuration CustomResourceDefinition: %v", err)
|
||||
}
|
||||
|
||||
if configObjectName := os.Getenv("POSTGRES_OPERATOR_CONFIGURATION_OBJECT"); configObjectName != "" {
|
||||
if config, err := c.readOperatorConfigurationFromCRD(configObjectName); err != nil {
|
||||
c.logger.Fatalf("unable to read operator configuration: %v", err)
|
||||
} else {
|
||||
c.logger.Fatalf("operator configuration: %#v", config)
|
||||
}
|
||||
}
|
||||
|
||||
if infraRoles, err := c.getInfrastructureRoles(&c.opConfig.InfrastructureRolesSecretName); err != nil {
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"github.com/zalando-incubator/postgres-operator/pkg/util/constants"
|
||||
|
||||
"github.com/zalando-incubator/postgres-operator/pkg/util/config"
|
||||
)
|
||||
|
||||
|
||||
func (c *Controller) readOperatorConfigurationFromCRD(configObjectName string) (*config.OperatorConfiguration, error){
|
||||
var (
|
||||
config config.OperatorConfiguration
|
||||
)
|
||||
|
||||
req := c.KubeClient.CRDREST.Get().
|
||||
Name(configObjectName).
|
||||
Namespace(c.opConfig.WatchedNamespace).
|
||||
Resource(constants.OperatorConfigCRDResource).
|
||||
VersionedParams(&metav1.ListOptions{ResourceVersion: "0"}, metav1.ParameterCodec)
|
||||
|
||||
data, err := req.DoRaw();
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not get operator configuration object %s: %v", configObjectName, err)
|
||||
}
|
||||
if err = json.Unmarshal(data, &config); err != nil {
|
||||
return nil, fmt.Errorf("could not unmarshal operator configuration object %s, %v", configObjectName, err)
|
||||
}
|
||||
|
||||
return &config, nil
|
||||
}
|
||||
@@ -48,7 +48,7 @@ func (c *Controller) clusterListFunc(options metav1.ListOptions) (runtime.Object
|
||||
req := c.KubeClient.CRDREST.
|
||||
Get().
|
||||
Namespace(c.opConfig.WatchedNamespace).
|
||||
Resource(constants.CRDResource).
|
||||
Resource(constants.PostgresCRDResource).
|
||||
VersionedParams(&options, metav1.ParameterCodec)
|
||||
|
||||
b, err := req.DoRaw()
|
||||
@@ -117,7 +117,7 @@ func (c *Controller) clusterWatchFunc(options metav1.ListOptions) (watch.Interfa
|
||||
r, err := c.KubeClient.CRDREST.
|
||||
Get().
|
||||
Namespace(c.opConfig.WatchedNamespace).
|
||||
Resource(constants.CRDResource).
|
||||
Resource(constants.PostgresCRDResource).
|
||||
VersionedParams(&options, metav1.ParameterCodec).
|
||||
FieldsSelectorParam(nil).
|
||||
Stream()
|
||||
|
||||
+15
-7
@@ -47,20 +47,20 @@ func (c *Controller) clusterWorkerID(clusterName spec.NamespacedName) uint32 {
|
||||
return c.clusterWorkers[clusterName]
|
||||
}
|
||||
|
||||
func (c *Controller) createCRD() error {
|
||||
func (c *Controller) createZalandoCRD(plural, singular, short string) error {
|
||||
crd := &apiextv1beta1.CustomResourceDefinition{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: constants.CRDResource + "." + constants.CRDGroup,
|
||||
Name: plural + "." + constants.CRDGroup,
|
||||
},
|
||||
Spec: apiextv1beta1.CustomResourceDefinitionSpec{
|
||||
Group: constants.CRDGroup,
|
||||
Version: constants.CRDApiVersion,
|
||||
Names: apiextv1beta1.CustomResourceDefinitionNames{
|
||||
Plural: constants.CRDResource,
|
||||
Singular: constants.CRDKind,
|
||||
ShortNames: []string{constants.CRDShort},
|
||||
Kind: constants.CRDKind,
|
||||
ListKind: constants.CRDKind + "List",
|
||||
Plural: plural,
|
||||
Singular: singular,
|
||||
ShortNames: []string{short},
|
||||
Kind: singular,
|
||||
ListKind: singular + "List",
|
||||
},
|
||||
Scope: apiextv1beta1.NamespaceScoped,
|
||||
},
|
||||
@@ -98,6 +98,14 @@ func (c *Controller) createCRD() error {
|
||||
})
|
||||
}
|
||||
|
||||
func (c *Controller) createPostgresCRD() error {
|
||||
return c.createZalandoCRD(constants.PostgresCRDResource, constants.PostgresCRDKind, constants.PostgresCRDShort)
|
||||
}
|
||||
|
||||
func (c *Controller) createOperatorCRD() error {
|
||||
return c.createZalandoCRD(constants.OperatorConfigCRDResource, constants.OperatorConfigCRDKind, constants.OperatorConfigCRDShort)
|
||||
}
|
||||
|
||||
func readDecodedRole(s string) (*spec.PgUser, error) {
|
||||
var result spec.PgUser
|
||||
if err := yaml.Unmarshal([]byte(s), &result); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user