Files
my-rook-config/pkg/operator/cassandra/controller/sync.go
T
Yannis Zarkadas c8c38d8584 cassandra: controller implementation
Control logic for the cassandra controller.
The controller exists in a separate StatefulSet, watches
Kubernetes Objects for changes and acts on those changes to
achieve the desired state.

Signed-off-by: Yannis Zarkadas <yanniszarkadas@gmail.com>
2018-12-05 12:46:33 +02:00

93 lines
2.4 KiB
Go
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/*
Copyright 2018 The Rook Authors. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
    http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package controller
import (
cassandrav1alpha1 "github.com/rook/rook/pkg/apis/cassandra.rook.io/v1alpha1"
corev1 "k8s.io/api/core/v1"
)
const (
// SuccessSynced is used as part of the Event 'reason' when a Cluster is
// synced.
SuccessSynced = "Synced"
// ErrResourceExists is used as part of the Event 'reason' when a
// Cluster fails to sync due to a resource of the same name already
// existing.
ErrSyncFailed = "ErrSyncFailed"
MessageRackCreated = "Rack %s created"
MessageRackScaledUp = "Rack %s scaled up to %d members"
// Messages to display when experiencing an error.
MessageHeadlessServiceSyncFailed = "Failed to sync Headless Service for cluster"
MessageMemberServicesSyncFailed = "Failed to sync MemberServices for cluster"
MessageUpdateStatusFailed = "Failed to update status for cluster"
MessageClusterSyncFailed = "Failed to sync cluster"
)
// Sync attempts to sync the given Cassandra Cluster.
// NOTE: the Cluster Object is a DeepCopy. Modify at will.
func (cc *ClusterController) Sync(c *cassandrav1alpha1.Cluster) error {
// Sync Headless Service for Cluster
if err := cc.syncClusterHeadlessService(c); err != nil {
cc.recorder.Event(
c,
corev1.EventTypeWarning,
ErrSyncFailed,
MessageHeadlessServiceSyncFailed,
)
return err
}
// Sync Cluster Member Services
if err := cc.syncMemberServices(c); err != nil {
cc.recorder.Event(
c,
corev1.EventTypeWarning,
ErrSyncFailed,
MessageMemberServicesSyncFailed,
)
return err
}
// Update Status
if err := cc.updateStatus(c); err != nil {
cc.recorder.Event(
c,
corev1.EventTypeWarning,
ErrSyncFailed,
MessageUpdateStatusFailed,
)
return err
}
// Sync Cluster
if err := cc.syncCluster(c); err != nil {
cc.recorder.Event(
c,
corev1.EventTypeWarning,
ErrSyncFailed,
MessageClusterSyncFailed,
)
return err
}
return nil
}