Merge pull request #1165 from travisn/handle-update

Only respond to crd updates when certain properties change
This commit is contained in:
Travis Nielsen authored and GitHub committed 2017-11-02 09:04:28 -07:00
commit ee9e5d41c2
8 files changed
+210 -10

No files matched your search

+16 -1
View File
@@ -166,7 +166,17 @@ func (c *ClusterController) onAdd(obj interface{}) {
}
func (c *ClusterController) onUpdate(oldObj, newObj interface{}) {
logger.Infof("modifying a cluster not implemented")
oldCluster := oldObj.(*Cluster)
newCluster := newObj.(*Cluster)
if !clusterChanged(oldCluster.Spec, newCluster.Spec) {
logger.Debugf("no updates made in the cluster")
return
}
logger.Infof("updating cluster %s", newCluster.Namespace)
if err := newCluster.createInstance(); err != nil {
logger.Errorf("failed to update cluster %s in namespace %s. %+v", newCluster.Name, newCluster.Namespace, err)
}
}
func (c *ClusterController) onDelete(obj interface{}) {
@@ -283,3 +293,8 @@ func (c *Cluster) createInitialCrushMap() error {
return nil
}
func clusterChanged(oldCluster, newCluster ClusterSpec) bool {
// no updates to the cluster supported yet
return false
}
+8
View File
@@ -51,3 +51,11 @@ func TestCreateInitialCrushMap(t *testing.T) {
err = c.createInitialCrushMap()
assert.Nil(t, err)
}
func TestClusterChanged(t *testing.T) {
old := ClusterSpec{VersionTag: "v0.6.0", MonCount: 1, HostNetwork: false}
new := ClusterSpec{VersionTag: "v0.7.0", MonCount: 3, HostNetwork: true}
// no changes supported yet
assert.False(t, clusterChanged(old, new))
}
+25 -4
View File
@@ -84,13 +84,18 @@ func (c *FilesystemController) onAdd(obj interface{}) {
}
func (c *FilesystemController) onUpdate(oldObj, newObj interface{}) {
//oldFilesystem := oldObj.(*Filesystem)
newFilesystem := newObj.(*Filesystem)
oldFS := oldObj.(*Filesystem)
newFS := newObj.(*Filesystem)
if !filesystemChanged(oldFS.Spec, newFS.Spec) {
logger.Debugf("filesystem %s not updated", newFS.Name)
return
}
// if the file system is modified, allow the file system to be created if it wasn't already
err := newFilesystem.Create(c.context, c.versionTag, c.hostNetwork)
logger.Infof("updating filesystem %s", newFS)
err := newFS.Create(c.context, c.versionTag, c.hostNetwork)
if err != nil {
logger.Errorf("failed to create (modify) file system %s. %+v", newFilesystem.Name, err)
logger.Errorf("failed to create (modify) file system %s. %+v", newFS.Name, err)
}
}
@@ -101,3 +106,19 @@ func (c *FilesystemController) onDelete(obj interface{}) {
logger.Errorf("failed to delete file system %s. %+v", filesystem.Name, err)
}
}
func filesystemChanged(oldFS, newFS FilesystemSpec) bool {
if len(oldFS.DataPools) != len(newFS.DataPools) {
logger.Infof("number of data pools changed from %d to %d", len(oldFS.DataPools), len(newFS.DataPools))
return true
}
if oldFS.MetadataServer.ActiveCount != newFS.MetadataServer.ActiveCount {
logger.Infof("number of mds active changed from %d to %d", oldFS.MetadataServer.ActiveCount, newFS.MetadataServer.ActiveCount)
return true
}
if oldFS.MetadataServer.ActiveStandby != newFS.MetadataServer.ActiveStandby {
logger.Infof("mds active standby changed from %t to %t", oldFS.MetadataServer.ActiveStandby, newFS.MetadataServer.ActiveStandby)
return true
}
return false
}
+42
View File
@@ -0,0 +1,42 @@
/*
Copyright 2016 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.
Some of the code below came from https://github.com/coreos/etcd-operator
which also has the apache 2.0 license.
*/
// Package mds to manage a rook file system.
package mds
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestFilesystemChanged(t *testing.T) {
// no change
old := FilesystemSpec{MetadataServer: MetadataServerSpec{ActiveCount: 1, ActiveStandby: true}}
new := FilesystemSpec{MetadataServer: MetadataServerSpec{ActiveCount: 1, ActiveStandby: true}}
changed := filesystemChanged(old, new)
assert.False(t, changed)
// changed properties
new = FilesystemSpec{MetadataServer: MetadataServerSpec{ActiveCount: 2, ActiveStandby: true}}
assert.True(t, filesystemChanged(old, new))
new = FilesystemSpec{MetadataServer: MetadataServerSpec{ActiveCount: 1, ActiveStandby: false}}
assert.True(t, filesystemChanged(old, new))
}
+13
View File
@@ -103,13 +103,26 @@ func (c *PoolController) onUpdate(oldObj, newObj interface{}) {
logger.Errorf("failed to update pool %s. erasurecoded update not allowed", pool.Name)
return
}
if !poolChanged(oldPool.Spec, pool.Spec) {
logger.Debugf("pool %s not changed", pool.Name)
return
}
// if the pool is modified, allow the pool to be created if it wasn't already
logger.Infof("updating pool %s", pool.Name)
if err := pool.create(c.context); err != nil {
logger.Errorf("failed to create (modify) pool %s. %+v", pool.ObjectMeta.Name, err)
}
}
func poolChanged(old, new PoolSpec) bool {
if old.Replicated.Size != new.Replicated.Size {
logger.Infof("pool replication changed from %d to %d", old.Replicated.Size, new.Replicated.Size)
return true
}
return false
}
func (c *PoolController) onDelete(obj interface{}) {
pool := obj.(*Pool)
if err := pool.delete(c.context); err != nil {
+14
View File
@@ -123,6 +123,20 @@ func TestCreatePool(t *testing.T) {
assert.Nil(t, err)
}
func TestUpdatePool(t *testing.T) {
// the pool did not change for properties that are updatable
old := PoolSpec{FailureDomain: "osd", ErasureCoded: ErasureCodedSpec{CodingChunks: 2, DataChunks: 2}}
new := PoolSpec{FailureDomain: "host", ErasureCoded: ErasureCodedSpec{CodingChunks: 3, DataChunks: 3}}
changed := poolChanged(old, new)
assert.False(t, changed)
// the pool changed for properties that are updatable
old = PoolSpec{FailureDomain: "osd", Replicated: ReplicatedSpec{Size: 1}}
new = PoolSpec{FailureDomain: "osd", Replicated: ReplicatedSpec{Size: 2}}
changed = poolChanged(old, new)
assert.True(t, changed)
}
func TestDeletePool(t *testing.T) {
executor := &exectest.MockExecutor{
MockExecuteCommandWithOutputFile: func(debug bool, actionName, command, outfile string, args ...string) (string, error) {
+42 -5
View File
@@ -84,13 +84,18 @@ func (c *ObjectStoreController) onAdd(obj interface{}) {
}
func (c *ObjectStoreController) onUpdate(oldObj, newObj interface{}) {
//oldObjectStore := oldObj.(*ObjectStore)
newObjectStore := newObj.(*ObjectStore)
// if the object store spec is modified, update the object store
oldStore := oldObj.(*ObjectStore)
newStore := newObj.(*ObjectStore)
if !storeChanged(oldStore.Spec, newStore.Spec) {
logger.Debugf("object store %s did not change", newStore.Name)
return
}
// if the object store is modified, allow the object store to be created if it wasn't already
err := newObjectStore.Update(c.context, c.versionTag, c.hostNetwork)
logger.Infof("applying object store %s changes", newStore.Name)
err := newStore.Update(c.context, c.versionTag, c.hostNetwork)
if err != nil {
logger.Errorf("failed to create (modify) object store %s. %+v", newObjectStore.Name, err)
logger.Errorf("failed to create (modify) object store %s. %+v", newStore.Name, err)
}
}
@@ -101,3 +106,35 @@ func (c *ObjectStoreController) onDelete(obj interface{}) {
logger.Errorf("failed to delete object store %s. %+v", objectStore.Name, err)
}
}
func storeChanged(oldStore, newStore ObjectStoreSpec) bool {
if oldStore.DataPool.Replicated.Size != newStore.DataPool.Replicated.Size {
logger.Infof("data pool replication changed from %d to %d", oldStore.DataPool.Replicated.Size, newStore.DataPool.Replicated.Size)
return true
}
if oldStore.MetadataPool.Replicated.Size != newStore.MetadataPool.Replicated.Size {
logger.Infof("metadata pool replication changed from %d to %d", oldStore.MetadataPool.Replicated.Size, newStore.MetadataPool.Replicated.Size)
return true
}
if oldStore.Gateway.Instances != newStore.Gateway.Instances {
logger.Infof("RGW instances changed from %d to %d", oldStore.Gateway.Instances, newStore.Gateway.Instances)
return true
}
if oldStore.Gateway.Port != newStore.Gateway.Port {
logger.Infof("Port changed from %d to %d", oldStore.Gateway.Port, newStore.Gateway.Port)
return true
}
if oldStore.Gateway.SecurePort != newStore.Gateway.SecurePort {
logger.Infof("SecurePort changed from %d to %d", oldStore.Gateway.SecurePort, newStore.Gateway.SecurePort)
return true
}
if oldStore.Gateway.AllNodes != newStore.Gateway.AllNodes {
logger.Infof("AllNodes changed from %t to %t", oldStore.Gateway.AllNodes, newStore.Gateway.AllNodes)
return true
}
if oldStore.Gateway.SSLCertificateRef != newStore.Gateway.SSLCertificateRef {
logger.Infof("SSLCertificateRef changed from %s to %s", oldStore.Gateway.SSLCertificateRef, newStore.Gateway.SSLCertificateRef)
return true
}
return false
}
+50
View File
@@ -0,0 +1,50 @@
/*
Copyright 2016 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.
Some of the code below came from https://github.com/coreos/etcd-operator
which also has the apache 2.0 license.
*/
// Package rgw to manage a rook object store.
package rgw
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestObjectStoreChanged(t *testing.T) {
old := ObjectStoreSpec{Gateway: GatewaySpec{Port: 80, SecurePort: 443, Instances: 1, AllNodes: false, SSLCertificateRef: ""}}
new := ObjectStoreSpec{Gateway: GatewaySpec{Port: 80, SecurePort: 443, Instances: 1, AllNodes: false, SSLCertificateRef: ""}}
// nothing changed
assert.False(t, storeChanged(old, new))
// there was a change
new = ObjectStoreSpec{Gateway: GatewaySpec{Port: 81, SecurePort: 443, Instances: 1, AllNodes: false, SSLCertificateRef: ""}}
assert.True(t, storeChanged(old, new))
new = ObjectStoreSpec{Gateway: GatewaySpec{Port: 80, SecurePort: 444, Instances: 1, AllNodes: false, SSLCertificateRef: ""}}
assert.True(t, storeChanged(old, new))
new = ObjectStoreSpec{Gateway: GatewaySpec{Port: 80, SecurePort: 443, Instances: 2, AllNodes: false, SSLCertificateRef: ""}}
assert.True(t, storeChanged(old, new))
new = ObjectStoreSpec{Gateway: GatewaySpec{Port: 80, SecurePort: 443, Instances: 1, AllNodes: true, SSLCertificateRef: ""}}
assert.True(t, storeChanged(old, new))
new = ObjectStoreSpec{Gateway: GatewaySpec{Port: 80, SecurePort: 443, Instances: 1, AllNodes: false, SSLCertificateRef: "mysecret"}}
assert.True(t, storeChanged(old, new))
}