try to emit error for missing team name in cluster name
This commit is contained in:
parent
0e3fb9ec43
commit
7e6e316c3b
|
|
@ -102,7 +102,7 @@ func (p *Postgresql) UnmarshalJSON(data []byte) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
tmp.Error = err.Error()
|
tmp.Error = err.Error()
|
||||||
tmp.Status = PostgresStatus{PostgresClusterStatus: ClusterStatusInvalid}
|
tmp.Status.PostgresClusterStatus = ClusterStatusInvalid
|
||||||
|
|
||||||
*p = Postgresql(tmp)
|
*p = Postgresql(tmp)
|
||||||
|
|
||||||
|
|
@ -112,10 +112,10 @@ func (p *Postgresql) UnmarshalJSON(data []byte) error {
|
||||||
|
|
||||||
if clusterName, err := extractClusterName(tmp2.ObjectMeta.Name, tmp2.Spec.TeamID); err != nil {
|
if clusterName, err := extractClusterName(tmp2.ObjectMeta.Name, tmp2.Spec.TeamID); err != nil {
|
||||||
tmp2.Error = err.Error()
|
tmp2.Error = err.Error()
|
||||||
tmp2.Status = PostgresStatus{PostgresClusterStatus: ClusterStatusInvalid}
|
tmp2.Status.PostgresClusterStatus = ClusterStatusInvalid
|
||||||
} else if err := validateCloneClusterDescription(&tmp2.Spec.Clone); err != nil {
|
} else if err := validateCloneClusterDescription(&tmp2.Spec.Clone); err != nil {
|
||||||
tmp2.Error = err.Error()
|
tmp2.Error = err.Error()
|
||||||
tmp2.Status = PostgresStatus{PostgresClusterStatus: ClusterStatusInvalid}
|
tmp2.Status.PostgresClusterStatus = ClusterStatusInvalid
|
||||||
} else {
|
} else {
|
||||||
tmp2.Spec.ClusterName = clusterName
|
tmp2.Spec.ClusterName = clusterName
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,9 @@ import (
|
||||||
v1 "k8s.io/api/core/v1"
|
v1 "k8s.io/api/core/v1"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apimachinery/pkg/types"
|
"k8s.io/apimachinery/pkg/types"
|
||||||
|
"k8s.io/client-go/kubernetes/scheme"
|
||||||
"k8s.io/client-go/tools/cache"
|
"k8s.io/client-go/tools/cache"
|
||||||
|
"k8s.io/client-go/tools/reference"
|
||||||
|
|
||||||
acidv1 "github.com/zalando/postgres-operator/pkg/apis/acid.zalan.do/v1"
|
acidv1 "github.com/zalando/postgres-operator/pkg/apis/acid.zalan.do/v1"
|
||||||
"github.com/zalando/postgres-operator/pkg/cluster"
|
"github.com/zalando/postgres-operator/pkg/cluster"
|
||||||
|
|
@ -420,18 +422,23 @@ func (c *Controller) queueClusterEvent(informerOldSpec, informerNewSpec *acidv1.
|
||||||
clusterError = informerNewSpec.Error
|
clusterError = informerNewSpec.Error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
workerID := c.clusterWorkerID(clusterName)
|
||||||
|
lg := c.logger.WithField("worker", workerID).WithField("cluster-name", clusterName)
|
||||||
|
|
||||||
if clusterError != "" && eventType != EventDelete {
|
if clusterError != "" && eventType != EventDelete {
|
||||||
c.logger.
|
lg.Errorf("skipping %q event for the invalid cluster: %s", eventType, clusterError)
|
||||||
WithField("cluster-name", clusterName).
|
ref, err := reference.GetReference(scheme.Scheme, informerNewSpec)
|
||||||
Debugf("skipping %q event for the invalid cluster: %s", eventType, clusterError)
|
if err != nil {
|
||||||
|
lg.Errorf("could not get reference for Postgresql CR %v/%v: %v", informerNewSpec.Namespace, informerNewSpec.Name, err)
|
||||||
|
}
|
||||||
|
c.eventRecorder.Eventf(ref, v1.EventTypeWarning, strings.Title(strings.ToLower(string(eventType))), "%v", clusterError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Don't pass the spec directly from the informer, since subsequent modifications of it would be reflected
|
// Don't pass the spec directly from the informer, since subsequent modifications of it would be reflected
|
||||||
// in the informer internal state, making it incohherent with the actual Kubernetes object (and, as a side
|
// in the informer internal state, making it incoherent with the actual Kubernetes object (and, as a side
|
||||||
// effect, the modified state will be returned together with subsequent events).
|
// effect, the modified state will be returned together with subsequent events).
|
||||||
|
|
||||||
workerID := c.clusterWorkerID(clusterName)
|
|
||||||
clusterEvent := ClusterEvent{
|
clusterEvent := ClusterEvent{
|
||||||
EventTime: time.Now(),
|
EventTime: time.Now(),
|
||||||
EventType: eventType,
|
EventType: eventType,
|
||||||
|
|
@ -441,7 +448,6 @@ func (c *Controller) queueClusterEvent(informerOldSpec, informerNewSpec *acidv1.
|
||||||
WorkerID: workerID,
|
WorkerID: workerID,
|
||||||
}
|
}
|
||||||
|
|
||||||
lg := c.logger.WithField("worker", workerID).WithField("cluster-name", clusterName)
|
|
||||||
if err := c.clusterEventQueues[workerID].Add(clusterEvent); err != nil {
|
if err := c.clusterEventQueues[workerID].Add(clusterEvent); err != nil {
|
||||||
lg.Errorf("error while queueing cluster event: %v", clusterEvent)
|
lg.Errorf("error while queueing cluster event: %v", clusterEvent)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue