Skip to content

Commit 7943068

Browse files
authored
Merge branch 'main' into improvement/MK8s-79-mount-hardware-tools
2 parents f5f196d + 356becd commit 7943068

21 files changed

Lines changed: 131 additions & 117 deletions

.github/renovate.json

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
3+
"extends": [
4+
"config:recommended",
5+
"abandonments:recommended"
6+
],
7+
8+
"packageRules": [
9+
{
10+
"matchDatasources": ["go"],
11+
"matchManagers": ["gomod"],
12+
"groupName": "golang-dependencies",
13+
"postUpdateOptions": ["gomodTidy"],
14+
"major": {
15+
"automerge": false,
16+
"addLabels": ["major-version-golang-dep", "manual-review"],
17+
"prBody": "Major Golang dependency update detected. **Requires manual review and merge.**",
18+
"prFooter": ""
19+
},
20+
"minor": {
21+
"automerge": false,
22+
"addLabels": ["minor-version-golang-dep"],
23+
"prBody": "Minor Golang dependency update. Merging automatically if tests pass.",
24+
"prFooter": ""
25+
},
26+
"patch": {
27+
"automerge": false,
28+
"addLabels": ["patch-version-golang-dep"],
29+
"prBody": "Patch Golang dependency update. Merging automatically if tests pass.",
30+
"prFooter": ""
31+
}
32+
}
33+
]
34+
}

api/v1alpha1/discoveredphysicaldisk_types.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ type DiscoveredPhysicalDiskStatus struct {
7070
WWN *string `json:"wwn,omitempty"`
7171
// Size is the disk capacity in bytes.
7272
// +optional
73-
Size *int64 `json:"size,omitempty"`
73+
Size *uint64 `json:"size,omitempty"`
7474
// Type is the disk media type.
7575
// +kubebuilder:validation:Enum=HDD;SSD;NVMe
7676
// +optional
@@ -79,7 +79,6 @@ type DiscoveredPhysicalDiskStatus struct {
7979
// +optional
8080
JBOD *bool `json:"jbod,omitempty"`
8181
// Status is the current disk status.
82-
// +kubebuilder:validation:Enum=Used;Available;Failed
8382
// +optional
8483
Status *string `json:"status,omitempty"`
8584
// Reason provides additional context for the current status.
@@ -95,7 +94,9 @@ type DiscoveredPhysicalDiskStatus struct {
9594

9695
// +kubebuilder:object:root=true
9796
// +kubebuilder:subresource:status
97+
// +kubebuilder:resource:scope=Cluster
9898
// +kubebuilder:selectablefield:JSONPath=`.spec.nodeName`
99+
// +kubebuilder:printcolumn:name="ID",type=string,JSONPath=`.spec.id`
99100
// +kubebuilder:printcolumn:name="Node",type=string,JSONPath=`.spec.nodeName`
100101
// +kubebuilder:printcolumn:name="Available",type=boolean,JSONPath=`.status.available`
101102
// +kubebuilder:printcolumn:name="Type",type=string,JSONPath=`.status.type`

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/main.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,9 @@ func main() {
262262

263263
// Build the allowed service account identity from the pod's own namespace
264264
// and service account name (injected via the Kubernetes downward API).
265+
// As a side note:
266+
// In the future, we'll implement proper role based access control in metalk8s.
267+
// A solution like kyverno could be used to enforce RBAC policies.
265268
podServiceAccount := os.Getenv("POD_SERVICE_ACCOUNT")
266269
if podNamespace == "" || podServiceAccount == "" {
267270
setupLog.Info("WARNING: POD_NAMESPACE and/or POD_SERVICE_ACCOUNT environment variables are not set; " +

config/crd/bases/metalk8s.scality.com_discoveredphysicaldisks.yaml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,12 @@ spec:
1212
listKind: DiscoveredPhysicalDiskList
1313
plural: discoveredphysicaldisks
1414
singular: discoveredphysicaldisk
15-
scope: Namespaced
15+
scope: Cluster
1616
versions:
1717
- additionalPrinterColumns:
18+
- jsonPath: .spec.id
19+
name: ID
20+
type: string
1821
- jsonPath: .spec.nodeName
1922
name: Node
2023
type: string
@@ -136,10 +139,6 @@ spec:
136139
type: integer
137140
status:
138141
description: Status is the current disk status.
139-
enum:
140-
- Used
141-
- Available
142-
- Failed
143142
type: string
144143
type:
145144
description: Type is the disk media type.

internal/controller/discoveredphysicaldisk_controller.go

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ import (
2121
"fmt"
2222
"time"
2323

24-
"github.com/scality/raidmgmt/pkg/domain/entities/physicaldrive"
2524
"k8s.io/apimachinery/pkg/runtime"
25+
"k8s.io/utils/ptr"
2626
ctrl "sigs.k8s.io/controller-runtime"
2727
"sigs.k8s.io/controller-runtime/pkg/client"
2828
"sigs.k8s.io/controller-runtime/pkg/event"
@@ -84,7 +84,7 @@ func (r *DiscoveredPhysicalDiskReconciler) Reconcile(ctx context.Context, req ct
8484

8585
// mapDriveToStatus writes the reconcile result onto the CR status.
8686
func mapDriveToStatus(status *metalk8sv1alpha1.DiscoveredPhysicalDiskStatus, result usecase.PhysicalDriveReconcileResult) {
87-
status.Available = ptr(result.Available)
87+
status.Available = ptr.To(result.Available)
8888

8989
if !result.Available {
9090
return
@@ -96,32 +96,15 @@ func mapDriveToStatus(status *metalk8sv1alpha1.DiscoveredPhysicalDiskStatus, res
9696
status.Model = &drive.Model
9797
status.Serial = &drive.Serial
9898
status.WWN = &drive.WWN
99-
status.Size = ptr(int64(drive.Size)) //nolint:gosec // raidmgmt uses uint64; overflow is not a concern for disk sizes
100-
status.Type = ptr(drive.Type.String())
99+
status.Size = &drive.Size
100+
status.Type = ptr.To(drive.Type.String())
101101
status.JBOD = &drive.JBOD
102-
status.Status = ptr(mapPDStatus(drive.Status))
102+
status.Status = ptr.To(drive.Status.String())
103103
status.Reason = &drive.Reason
104104
status.DevicePath = &drive.DevicePath
105105
status.PermanentPath = &drive.PermanentPath
106106
}
107107

108-
func mapPDStatus(status physicaldrive.PDStatus) string {
109-
switch status {
110-
case physicaldrive.PDStatusUsed:
111-
return "Used"
112-
case physicaldrive.PDStatusUnassignedGood:
113-
return "Available"
114-
case physicaldrive.PDStatusFailed, physicaldrive.PDStatusUnassignedBad:
115-
return "Failed"
116-
default:
117-
return ""
118-
}
119-
}
120-
121-
func ptr[T any](v T) *T {
122-
return &v
123-
}
124-
125108
// SetupWithManager sets up the controller with the Manager.
126109
// tickerEvents is a channel of GenericEvent sent by the DiscoveryTicker;
127110
// receiving on this channel will trigger reconciliation.

internal/controller/discoveredphysicaldisk_controller_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ var _ = Describe("DiscoveredPhysicalDisk Controller", func() {
137137
Expect(*updated.Status.Model).To(Equal("ST4000NM0033"))
138138
Expect(*updated.Status.Serial).To(Equal("Z1Z2Z3Z4"))
139139
Expect(*updated.Status.WWN).To(Equal("5000C50012345678"))
140-
Expect(*updated.Status.Size).To(Equal(int64(4000787030016)))
140+
Expect(*updated.Status.Size).To(Equal(uint64(4000787030016)))
141141
Expect(*updated.Status.Type).To(Equal("HDD"))
142142
Expect(*updated.Status.JBOD).To(BeTrue())
143143
Expect(*updated.Status.Status).To(Equal("Used"))

internal/controller/discovery_ticker_test.go

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,14 @@ var _ = Describe("DiscoveryTicker", func() {
4646
NodeName: "test-node",
4747
Interval: 100 * time.Millisecond,
4848
EventChan: eventChan,
49-
UseCase: usecase.NewDiscoverPhysicalDrives(logr.Discard(), nil, nil, nil, &noopCacheWriter{}, "test-node", "default"),
49+
UseCase: usecase.NewDiscoverPhysicalDrives(
50+
logr.Discard(),
51+
[]service.PhysicalDriveDiscoverer{},
52+
[]service.LogicalVolumeDiscoverer{},
53+
nil,
54+
&noopCacheWriter{},
55+
"test-node",
56+
),
5057
}
5158

5259
done := make(chan error, 1)
@@ -70,7 +77,14 @@ var _ = Describe("DiscoveryTicker", func() {
7077
NodeName: "test-node",
7178
Interval: 50 * time.Millisecond,
7279
EventChan: eventChan,
73-
UseCase: usecase.NewDiscoverPhysicalDrives(logr.Discard(), nil, nil, nil, &noopCacheWriter{}, "test-node", "default"),
80+
UseCase: usecase.NewDiscoverPhysicalDrives(
81+
logr.Discard(),
82+
[]service.PhysicalDriveDiscoverer{},
83+
[]service.LogicalVolumeDiscoverer{},
84+
nil,
85+
&noopCacheWriter{},
86+
"test-node",
87+
),
7488
}
7589

7690
tickCount := 0
@@ -110,7 +124,14 @@ var _ = Describe("DiscoveryTicker", func() {
110124
NodeName: "test-node",
111125
Interval: time.Hour, // Long interval; should not matter.
112126
EventChan: eventChan,
113-
UseCase: usecase.NewDiscoverPhysicalDrives(logr.Discard(), nil, nil, nil, &noopCacheWriter{}, "test-node", "default"),
127+
UseCase: usecase.NewDiscoverPhysicalDrives(
128+
logr.Discard(),
129+
[]service.PhysicalDriveDiscoverer{},
130+
[]service.LogicalVolumeDiscoverer{},
131+
nil,
132+
&noopCacheWriter{},
133+
"test-node",
134+
),
114135
}
115136

116137
done := make(chan error, 1)

internal/controller/status_mapping_test.go

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -28,26 +28,6 @@ import (
2828
"disk-management-agent/pkg/usecase"
2929
)
3030

31-
func TestMapPDStatus(t *testing.T) {
32-
tests := []struct {
33-
name string
34-
status physicaldrive.PDStatus
35-
expected string
36-
}{
37-
{"Used", physicaldrive.PDStatusUsed, "Used"},
38-
{"Available", physicaldrive.PDStatusUnassignedGood, "Available"},
39-
{"Failed", physicaldrive.PDStatusFailed, "Failed"},
40-
{"UnassignedBad", physicaldrive.PDStatusUnassignedBad, "Failed"},
41-
{"Unknown", physicaldrive.PDStatusUnknown, ""},
42-
}
43-
44-
for _, tt := range tests {
45-
t.Run(tt.name, func(t *testing.T) {
46-
assert.Equal(t, tt.expected, mapPDStatus(tt.status))
47-
})
48-
}
49-
}
50-
5131
func TestMapDriveToStatus_Available(t *testing.T) {
5232
result := usecase.PhysicalDriveReconcileResult{
5333
CacheReady: true,
@@ -81,7 +61,7 @@ func TestMapDriveToStatus_Available(t *testing.T) {
8161
assert.Equal(t, "ST4000NM0033", *status.Model)
8262
assert.Equal(t, "Z1Z2Z3Z4", *status.Serial)
8363
assert.Equal(t, "5000C50012345678", *status.WWN)
84-
assert.Equal(t, int64(4000787030016), *status.Size)
64+
assert.Equal(t, uint64(4000787030016), *status.Size)
8565
assert.Equal(t, "HDD", *status.Type)
8666
assert.True(t, *status.JBOD)
8767
assert.Equal(t, "Used", *status.Status)

internal/webhook/v1alpha1/discoveredphysicaldisk_webhook_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ func newTestValidator() *DiscoveredPhysicalDiskCustomValidator {
4141
func newTestDisk() *metalk8sv1alpha1.DiscoveredPhysicalDisk {
4242
return &metalk8sv1alpha1.DiscoveredPhysicalDisk{
4343
ObjectMeta: metav1.ObjectMeta{
44-
Name: "test-disk",
45-
Namespace: "default",
44+
Name: "test-disk",
4645
},
4746
Spec: metalk8sv1alpha1.DiscoveredPhysicalDiskSpec{
4847
NodeName: "node-1",

0 commit comments

Comments
 (0)