Files
my-rook-config/pkg/operator/ceph/object/spec_test.go
T

158 lines
4.7 KiB
Go
Raw Normal View History

2018-10-09 21:43:24 -06:00
/*
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.
*/
package object
import (
2019-06-13 13:00:22 +02:00
"fmt"
2018-10-09 21:43:24 -06:00
"testing"
cephv1 "github.com/rook/rook/pkg/apis/ceph.rook.io/v1"
2018-10-09 21:43:24 -06:00
"github.com/rook/rook/pkg/clusterd"
2019-02-14 09:16:21 -07:00
cephconfig "github.com/rook/rook/pkg/operator/ceph/config"
cephtest "github.com/rook/rook/pkg/operator/ceph/test"
cephver "github.com/rook/rook/pkg/operator/ceph/version"
2019-02-14 09:16:21 -07:00
testop "github.com/rook/rook/pkg/operator/test"
2018-10-09 21:43:24 -06:00
exectest "github.com/rook/rook/pkg/util/exec/test"
"github.com/stretchr/testify/assert"
v1 "k8s.io/api/core/v1"
2018-10-09 21:43:24 -06:00
"k8s.io/apimachinery/pkg/api/resource"
)
func TestPodSpecs(t *testing.T) {
store := simpleStore()
store.Spec.Gateway.Resources = v1.ResourceRequirements{
Limits: v1.ResourceList{
2019-03-05 15:51:20 +01:00
v1.ResourceCPU: *resource.NewQuantity(200.0, resource.BinarySI),
v1.ResourceMemory: *resource.NewQuantity(1337.0, resource.BinarySI),
2018-10-09 21:43:24 -06:00
},
Requests: v1.ResourceList{
2019-03-05 15:51:20 +01:00
v1.ResourceCPU: *resource.NewQuantity(100.0, resource.BinarySI),
v1.ResourceMemory: *resource.NewQuantity(500.0, resource.BinarySI),
2018-10-09 21:43:24 -06:00
},
}
2019-08-04 15:40:29 -05:00
store.Spec.Gateway.PriorityClassName = "my-priority-class"
2019-02-14 09:16:21 -07:00
info := testop.CreateConfigDir(1)
info.CephVersion = cephver.Mimic
2019-04-02 20:10:09 +02:00
data := cephconfig.NewStatelessDaemonDataPathMap(cephconfig.RgwType, "default", "rook-ceph", "/var/lib/rook/")
2019-02-14 09:16:21 -07:00
c := &clusterConfig{
clusterInfo: info,
store: store,
rookVersion: "rook/rook:myversion",
clusterSpec: &cephv1.ClusterSpec{
CephVersion: cephv1.CephVersionSpec{Image: "ceph/ceph:v13.2.1"},
Network: cephv1.NetworkSpec{
HostNetwork: true,
},
},
2019-02-14 09:16:21 -07:00
DataPathMap: data,
}
2018-10-09 21:43:24 -06:00
2019-06-13 13:00:22 +02:00
resourceName := fmt.Sprintf("%s-%s", AppName, c.store.Name)
rgwConfig := &rgwConfig{
ResourceName: resourceName,
}
s := c.makeRGWPodSpec(rgwConfig)
2018-10-09 21:43:24 -06:00
2019-02-14 09:16:21 -07:00
podTemplate := cephtest.NewPodTemplateSpecTester(t, &s)
podTemplate.RunFullSuite(cephconfig.RgwType, "default", "rook-ceph-rgw", "mycluster", "ceph/ceph:myversion",
2019-08-04 15:40:29 -05:00
"200", "100", "1337", "500", /* resources */
"my-priority-class")
2018-10-09 21:43:24 -06:00
}
func TestSSLPodSpec(t *testing.T) {
store := simpleStore()
2019-02-14 09:16:21 -07:00
store.Spec.Gateway.Resources = v1.ResourceRequirements{
Limits: v1.ResourceList{
2019-03-05 15:51:20 +01:00
v1.ResourceCPU: *resource.NewQuantity(200.0, resource.BinarySI),
v1.ResourceMemory: *resource.NewQuantity(1337.0, resource.BinarySI),
2019-02-14 09:16:21 -07:00
},
Requests: v1.ResourceList{
2019-03-05 15:51:20 +01:00
v1.ResourceCPU: *resource.NewQuantity(100.0, resource.BinarySI),
v1.ResourceMemory: *resource.NewQuantity(500.0, resource.BinarySI),
2019-02-14 09:16:21 -07:00
},
}
2019-08-04 15:40:29 -05:00
store.Spec.Gateway.PriorityClassName = "my-priority-class"
2019-02-14 09:16:21 -07:00
info := testop.CreateConfigDir(1)
info.CephVersion = cephver.Mimic
2019-04-02 20:10:09 +02:00
data := cephconfig.NewStatelessDaemonDataPathMap(cephconfig.RgwType, "default", "rook-ceph", "/var/lib/rook/")
2018-10-09 21:43:24 -06:00
store.Spec.Gateway.SSLCertificateRef = "mycert"
store.Spec.Gateway.SecurePort = 443
2019-02-14 09:16:21 -07:00
c := &clusterConfig{
clusterInfo: info,
store: store,
rookVersion: "rook/rook:myversion",
clusterSpec: &cephv1.ClusterSpec{
CephVersion: cephv1.CephVersionSpec{Image: "ceph/ceph:v13.2.1"},
Network: cephv1.NetworkSpec{
HostNetwork: true,
},
},
2019-02-14 09:16:21 -07:00
DataPathMap: data,
}
2019-06-13 13:00:22 +02:00
resourceName := fmt.Sprintf("%s-%s", AppName, c.store.Name)
rgwConfig := &rgwConfig{
ResourceName: resourceName,
}
s := c.makeRGWPodSpec(rgwConfig)
2019-02-14 09:16:21 -07:00
podTemplate := cephtest.NewPodTemplateSpecTester(t, &s)
podTemplate.RunFullSuite(cephconfig.RgwType, "default", "rook-ceph-rgw", "mycluster", "ceph/ceph:myversion",
2019-08-04 15:40:29 -05:00
"200", "100", "1337", "500", /* resources */
"my-priority-class")
2019-02-14 09:16:21 -07:00
2018-10-09 21:43:24 -06:00
assert.True(t, s.Spec.HostNetwork)
assert.Equal(t, v1.DNSClusterFirstWithHostNet, s.Spec.DNSPolicy)
}
func TestValidateSpec(t *testing.T) {
context := &clusterd.Context{Executor: &exectest.MockExecutor{}}
// valid store
s := simpleStore()
err := validateStore(context, s)
assert.Nil(t, err)
// no name
s.Name = ""
err = validateStore(context, s)
assert.NotNil(t, err)
s.Name = "default"
err = validateStore(context, s)
assert.Nil(t, err)
// no namespace
s.Namespace = ""
err = validateStore(context, s)
assert.NotNil(t, err)
s.Namespace = "mycluster"
err = validateStore(context, s)
assert.Nil(t, err)
2019-11-05 17:16:08 +01:00
// no replication or EC is valid
2018-10-09 21:43:24 -06:00
s.Spec.MetadataPool.Replicated.Size = 0
err = validateStore(context, s)
2019-11-05 17:16:08 +01:00
assert.Nil(t, err)
2018-10-09 21:43:24 -06:00
s.Spec.MetadataPool.Replicated.Size = 1
err = validateStore(context, s)
assert.Nil(t, err)
}