Skip to content

Commit

Permalink
added slug
Browse files Browse the repository at this point in the history
Signed-off-by: Viktor Kramarenko <[email protected]>
  • Loading branch information
ViktorKram committed Aug 29, 2024
1 parent 33dff0e commit 5cfda70
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 12 deletions.
2 changes: 2 additions & 0 deletions images/agent/src/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ require (
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/pprof v0.0.0-20240525223248-4bfdf5a9a2af // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/gosimple/slug v1.14.0 // indirect
github.com/gosimple/unidecode v1.0.1 // indirect
github.com/imdario/mergo v0.3.16 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
Expand Down
4 changes: 4 additions & 0 deletions images/agent/src/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ github.com/google/pprof v0.0.0-20240525223248-4bfdf5a9a2af h1:kmjWCqn2qkEml422C2
github.com/google/pprof v0.0.0-20240525223248-4bfdf5a9a2af/go.mod h1:K1liHPHnj73Fdn/EKuT8nrFqBihUSKXoLYU0BuatOYo=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gosimple/slug v1.14.0 h1:RtTL/71mJNDfpUbCOmnf/XFkzKRtD6wL6Uy+3akm4Es=
github.com/gosimple/slug v1.14.0/go.mod h1:UiRaFH+GEilHstLUmcBgWcI42viBN7mAb818JrYOeFQ=
github.com/gosimple/unidecode v1.0.1 h1:hZzFTMMqSswvf0LBJZCZgThIZrpDHFXux9KeGmn6T/o=
github.com/gosimple/unidecode v1.0.1/go.mod h1:CP0Cr1Y1kogOtx0bJblKzsVWrqYaqfNOnHzpgWw4Awc=
github.com/imdario/mergo v0.3.16 h1:wwQJbIsHYGMUyLSPrEq1CT16AhnhNJQ51+4fdHUnCl4=
github.com/imdario/mergo v0.3.16/go.mod h1:WBLT9ZmE3lPoWsEzCh9LPo3TiwVN+ZKEjmz+hD27ysY=
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
Expand Down
22 changes: 12 additions & 10 deletions images/agent/src/pkg/controller/block_device.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"time"

"github.com/deckhouse/sds-node-configurator/api/v1alpha1"
"github.com/gosimple/slug"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
kclient "sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -548,22 +549,23 @@ func ConfigureBlockDeviceLabels(blockDevice v1alpha1.BlockDevice) map[string]str
labels[key] = value
}

labels[internal.MetadataNameLabelKey] = strings.ReplaceAll(blockDevice.ObjectMeta.Name, " ", "_")
labels[internal.HostNameLabelKey] = strings.ReplaceAll(blockDevice.Status.NodeName, " ", "_")
labels[internal.BlockDeviceTypeLabelKey] = strings.ReplaceAll(blockDevice.Status.Type, " ", "_")
labels[internal.BlockDeviceFSTypeLabelKey] = strings.ReplaceAll(blockDevice.Status.FsType, " ", "_")
slug.Lowercase = false
labels[internal.MetadataNameLabelKey] = slug.Make(blockDevice.ObjectMeta.Name)
labels[internal.HostNameLabelKey] = slug.Make(blockDevice.Status.NodeName)
labels[internal.BlockDeviceTypeLabelKey] = slug.Make(blockDevice.Status.Type)
labels[internal.BlockDeviceFSTypeLabelKey] = slug.Make(blockDevice.Status.FsType)
labels[internal.BlockDevicePVUUIDLabelKey] = blockDevice.Status.PVUuid
labels[internal.BlockDeviceVGUUIDLabelKey] = blockDevice.Status.VGUuid
labels[internal.BlockDevicePartUUIDLabelKey] = blockDevice.Status.PartUUID
labels[internal.BlockDeviceLVMVolumeGroupNameLabelKey] = strings.ReplaceAll(blockDevice.Status.LvmVolumeGroupName, " ", "_")
labels[internal.BlockDeviceActualVGNameLabelKey] = strings.ReplaceAll(blockDevice.Status.ActualVGNameOnTheNode, " ", "_")
labels[internal.BlockDeviceWWNLabelKey] = strings.ReplaceAll(blockDevice.Status.Wwn, " ", "_")
labels[internal.BlockDeviceSerialLabelKey] = strings.ReplaceAll(blockDevice.Status.Serial, " ", "_")
labels[internal.BlockDeviceLVMVolumeGroupNameLabelKey] = slug.Make(blockDevice.Status.LvmVolumeGroupName)
labels[internal.BlockDeviceActualVGNameLabelKey] = slug.Make(blockDevice.Status.ActualVGNameOnTheNode)
labels[internal.BlockDeviceWWNLabelKey] = slug.Make(blockDevice.Status.Wwn)
labels[internal.BlockDeviceSerialLabelKey] = slug.Make(blockDevice.Status.Serial)
labels[internal.BlockDeviceSizeLabelKey] = blockDevice.Status.Size.String()
labels[internal.BlockDeviceModelLabelKey] = strings.ReplaceAll(blockDevice.Status.Model, " ", "_")
labels[internal.BlockDeviceModelLabelKey] = slug.Make(blockDevice.Status.Model)
labels[internal.BlockDeviceRotaLabelKey] = strconv.FormatBool(blockDevice.Status.Rota)
labels[internal.BlockDeviceHotPlugLabelKey] = strconv.FormatBool(blockDevice.Status.HotPlug)
labels[internal.BlockDeviceMachineIDLabelKey] = strings.ReplaceAll(blockDevice.Status.MachineID, " ", "_")
labels[internal.BlockDeviceMachineIDLabelKey] = slug.Make(blockDevice.Status.MachineID)

return labels
}
Expand Down
5 changes: 3 additions & 2 deletions images/agent/src/pkg/controller/block_device_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ import (
"context"
"fmt"
"strconv"
"strings"
"testing"

"github.com/deckhouse/sds-node-configurator/api/v1alpha1"
"github.com/gosimple/slug"
"github.com/stretchr/testify/assert"
errors2 "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/resource"
Expand Down Expand Up @@ -346,6 +346,7 @@ func TestBlockDeviceCtrl(t *testing.T) {
"some-custom-label2": "v",
}

slug.Lowercase = false
expectedLabels := map[string]string{
internal.MetadataNameLabelKey: blockDevice.ObjectMeta.Name,
internal.HostNameLabelKey: blockDevice.Status.NodeName,
Expand All @@ -359,7 +360,7 @@ func TestBlockDeviceCtrl(t *testing.T) {
internal.BlockDeviceWWNLabelKey: blockDevice.Status.Wwn,
internal.BlockDeviceSerialLabelKey: blockDevice.Status.Serial,
internal.BlockDeviceSizeLabelKey: blockDevice.Status.Size.String(),
internal.BlockDeviceModelLabelKey: strings.ReplaceAll(blockDevice.Status.Model, " ", "_"),
internal.BlockDeviceModelLabelKey: slug.Make(blockDevice.Status.Model),
internal.BlockDeviceRotaLabelKey: strconv.FormatBool(blockDevice.Status.Rota),
internal.BlockDeviceHotPlugLabelKey: strconv.FormatBool(blockDevice.Status.HotPlug),
internal.BlockDeviceMachineIDLabelKey: blockDevice.Status.MachineID,
Expand Down

0 comments on commit 5cfda70

Please sign in to comment.