Skip to content

Commit

Permalink
Merge pull request #147 from cschwede/small-cleanups
Browse files Browse the repository at this point in the history
Small cleanups
  • Loading branch information
openshift-merge-bot[bot] authored Feb 26, 2024
2 parents c64ebea + a405664 commit 18b59ea
Show file tree
Hide file tree
Showing 12 changed files with 30 additions and 53 deletions.
22 changes: 0 additions & 22 deletions api/v1beta1/common_types.go

This file was deleted.

12 changes: 6 additions & 6 deletions controllers/swiftring_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ import (
"github.com/openstack-k8s-operators/lib-common/modules/common/env"
"github.com/openstack-k8s-operators/lib-common/modules/common/helper"
"github.com/openstack-k8s-operators/lib-common/modules/common/job"
"github.com/openstack-k8s-operators/lib-common/modules/common/secret"

swiftv1beta1 "github.com/openstack-k8s-operators/swift-operator/api/v1beta1"
"github.com/openstack-k8s-operators/swift-operator/pkg/swift"
"github.com/openstack-k8s-operators/swift-operator/pkg/swiftring"
batchv1 "k8s.io/api/batch/v1"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -117,10 +117,10 @@ func (r *SwiftRingReconciler) Reconcile(ctx context.Context, req ctrl.Request) (

serviceLabels := swiftring.Labels()

// Create a Secret populated with content from templates/
// Create a ConfigMap populated with content from templates/
envVars := make(map[string]env.Setter)
tpl := swiftring.SecretTemplates(instance, serviceLabels)
err = secret.EnsureSecrets(ctx, helper, instance, tpl, &envVars)
tpl := swiftring.ConfigMapTemplates(instance, serviceLabels)
err = configmap.EnsureConfigMaps(ctx, helper, instance, tpl, &envVars)
if err != nil {
return ctrl.Result{}, err
}
Expand All @@ -134,7 +134,7 @@ func (r *SwiftRingReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
// Check if the device list ConfigMap did change and if so, delete the
// rebalance Job. This will result in a new Job that rebalances with
// the updated device list
_, deviceListHash, err := configmap.GetConfigMapAndHashWithName(ctx, helper, swiftv1beta1.DeviceConfigMapName, instance.Namespace)
_, deviceListHash, err := configmap.GetConfigMapAndHashWithName(ctx, helper, swift.DeviceConfigMapName, instance.Namespace)
if err != nil {
return ctrl.Result{}, err
}
Expand Down Expand Up @@ -197,7 +197,7 @@ func (r *SwiftRingReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
func (r *SwiftRingReconciler) SetupWithManager(mgr ctrl.Manager) error {
deviceConfigMapFilter := func(ctx context.Context, o client.Object) []reconcile.Request {
result := []reconcile.Request{}
if o.GetName() == swiftv1beta1.DeviceConfigMapName {
if o.GetName() == swift.DeviceConfigMapName {
// There should be only one SwiftRing instance within
// the Namespace - that needs to be reconciled
swiftRings := &swiftv1beta1.SwiftRingList{}
Expand Down
3 changes: 2 additions & 1 deletion controllers/swiftstorage_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import (
"k8s.io/client-go/kubernetes"

swiftv1beta1 "github.com/openstack-k8s-operators/swift-operator/api/v1beta1"
"github.com/openstack-k8s-operators/swift-operator/pkg/swift"
"github.com/openstack-k8s-operators/swift-operator/pkg/swiftstorage"

"github.com/openstack-k8s-operators/lib-common/modules/common/condition"
Expand Down Expand Up @@ -144,7 +145,7 @@ func (r *SwiftStorageReconciler) Reconcile(ctx context.Context, req ctrl.Request
// not, create an initial device list to bootstrap the cluster with The
// weights are simply set to the requested size, this will be changed
// once all StatefulSets are running
_, ctrlResult, err := configmap.GetConfigMap(ctx, helper, instance, swiftv1beta1.DeviceConfigMapName, 5*time.Second)
_, ctrlResult, err := configmap.GetConfigMap(ctx, helper, instance, swift.DeviceConfigMapName, 5*time.Second)
if err != nil {
return ctrlResult, err
} else if (ctrlResult != ctrl.Result{}) {
Expand Down
4 changes: 3 additions & 1 deletion pkg/swift/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ const (
RunAsUser int64 = 42445
ProxyPort int32 = 8081
ProxyHttpdPort int32 = 8080
MemcachedPort int32 = 11211

AccountServerPort int32 = 6202
ContainerServerPort int32 = 6201
Expand All @@ -32,4 +31,7 @@ const (
ServiceDescription = "Swift Object Storage"

ClaimName = "srv"

RingConfigMapName = "swift-ring-files"
DeviceConfigMapName = "swift-storage-devices"
)
8 changes: 5 additions & 3 deletions pkg/swift/funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ limitations under the License.
package swift

import (
common "github.com/openstack-k8s-operators/lib-common/modules/common"
"github.com/openstack-k8s-operators/lib-common/modules/common"
"github.com/openstack-k8s-operators/lib-common/modules/common/affinity"

corev1 "k8s.io/api/core/v1"
"math/rand"
)
Expand All @@ -41,7 +40,10 @@ func GetSecurityContext() corev1.SecurityContext {
}

func Labels() map[string]string {
return map[string]string{"app.kubernetes.io/name": "Swift"}
return map[string]string{
common.AppSelector: ServiceName,
common.ComponentSelector: ServiceName, // identical in this case
}
}

func RandomString(length int) string {
Expand Down
3 changes: 2 additions & 1 deletion pkg/swiftproxy/volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package swiftproxy

import (
swiftv1beta1 "github.com/openstack-k8s-operators/swift-operator/api/v1beta1"
"github.com/openstack-k8s-operators/swift-operator/pkg/swift"
corev1 "k8s.io/api/core/v1"
)

Expand Down Expand Up @@ -45,7 +46,7 @@ func getProxyVolumes(instance *swiftv1beta1.SwiftProxy) []corev1.Volume {
VolumeSource: corev1.VolumeSource{
ConfigMap: &corev1.ConfigMapVolumeSource{
LocalObjectReference: corev1.LocalObjectReference{
Name: swiftv1beta1.RingConfigMapName,
Name: swift.RingConfigMapName,
},
},
},
Expand Down
2 changes: 1 addition & 1 deletion pkg/swiftring/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func GetRingJob(instance *swiftv1beta1.SwiftRing, labels map[string]string) *bat
securityContext := swift.GetSecurityContext()

envVars := map[string]env.Setter{}
envVars["CM_NAME"] = env.SetValue(swiftv1beta1.RingConfigMapName)
envVars["CM_NAME"] = env.SetValue(swift.RingConfigMapName)
envVars["NAMESPACE"] = env.SetValue(instance.Namespace)
envVars["SWIFT_PART_POWER"] = env.SetValue(fmt.Sprint(*instance.Spec.PartPower))
envVars["SWIFT_REPLICAS"] = env.SetValue(fmt.Sprint(*instance.Spec.RingReplicas))
Expand Down
13 changes: 1 addition & 12 deletions pkg/swiftring/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
swiftv1beta1 "github.com/openstack-k8s-operators/swift-operator/api/v1beta1"
)

func SecretTemplates(instance *swiftv1beta1.SwiftRing, labels map[string]string) []util.Template {
func ConfigMapTemplates(instance *swiftv1beta1.SwiftRing, labels map[string]string) []util.Template {
return []util.Template{
{
Name: fmt.Sprintf("%s-scripts", instance.Name),
Expand All @@ -33,14 +33,3 @@ func SecretTemplates(instance *swiftv1beta1.SwiftRing, labels map[string]string)
},
}
}

func ConfigMapTemplates(instance *swiftv1beta1.SwiftRing, labels map[string]string) []util.Template {
return []util.Template{
{
Name: swiftv1beta1.RingConfigMapName,
Namespace: instance.Namespace,
Type: util.TemplateTypeNone,
InstanceType: instance.Kind,
},
}
}
9 changes: 6 additions & 3 deletions pkg/swiftring/volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package swiftring

import (
swiftv1beta1 "github.com/openstack-k8s-operators/swift-operator/api/v1beta1"
"github.com/openstack-k8s-operators/swift-operator/pkg/swift"
corev1 "k8s.io/api/core/v1"
)

Expand All @@ -27,9 +28,11 @@ func getRingVolumes(instance *swiftv1beta1.SwiftRing) []corev1.Volume {
{
Name: "scripts",
VolumeSource: corev1.VolumeSource{
Secret: &corev1.SecretVolumeSource{
ConfigMap: &corev1.ConfigMapVolumeSource{
DefaultMode: &scriptsVolumeDefaultMode,
SecretName: instance.Name + "-scripts",
LocalObjectReference: corev1.LocalObjectReference{
Name: instance.Name + "-scripts",
},
},
},
},
Expand All @@ -52,7 +55,7 @@ func getRingVolumes(instance *swiftv1beta1.SwiftRing) []corev1.Volume {
VolumeSource: corev1.VolumeSource{
ConfigMap: &corev1.ConfigMapVolumeSource{
LocalObjectReference: corev1.LocalObjectReference{
Name: swiftv1beta1.DeviceConfigMapName,
Name: swift.DeviceConfigMapName,
},
},
},
Expand Down
2 changes: 1 addition & 1 deletion pkg/swiftstorage/dnsdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func DNSData(
// Create DNSData object
dnsData := &infranetworkv1.DNSData{
ObjectMeta: metav1.ObjectMeta{
Name: swiftPod.Name,
Name: "dns-" + swiftPod.Name,
Namespace: swiftPod.Namespace,
Labels: serviceLabels,
},
Expand Down
3 changes: 2 additions & 1 deletion pkg/swiftstorage/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"fmt"
"github.com/openstack-k8s-operators/lib-common/modules/common/util"
swiftv1beta1 "github.com/openstack-k8s-operators/swift-operator/api/v1beta1"
"github.com/openstack-k8s-operators/swift-operator/pkg/swift"
)

func ConfigMapTemplates(instance *swiftv1beta1.SwiftStorage, labels map[string]string, memcachedServers string) []util.Template {
Expand Down Expand Up @@ -58,7 +59,7 @@ func DeviceConfigMapTemplates(instance *swiftv1beta1.SwiftStorage, devices strin

return []util.Template{
{
Name: swiftv1beta1.DeviceConfigMapName,
Name: swift.DeviceConfigMapName,
Namespace: instance.Namespace,
Type: util.TemplateTypeNone,
InstanceType: instance.Kind,
Expand Down
2 changes: 1 addition & 1 deletion pkg/swiftstorage/volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func getStorageVolumes(instance *swiftv1beta1.SwiftStorage) []corev1.Volume {
VolumeSource: corev1.VolumeSource{
ConfigMap: &corev1.ConfigMapVolumeSource{
LocalObjectReference: corev1.LocalObjectReference{
Name: swiftv1beta1.RingConfigMapName,
Name: swift.RingConfigMapName,
},
},
},
Expand Down

0 comments on commit 18b59ea

Please sign in to comment.