Skip to content

Commit 09beffb

Browse files
Merge branch 'main' into bha-cpumemlimits
2 parents 5e11354 + 355e26a commit 09beffb

18 files changed

+371
-204
lines changed

.secrets.baseline

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"files": "go.sum|^.secrets.baseline$",
44
"lines": null
55
},
6-
"generated_at": "2024-06-03T09:31:24Z",
6+
"generated_at": "2024-06-12T11:19:05Z",
77
"plugins_used": [
88
{
99
"name": "AWSKeyDetector"

api/v1alpha1/recoverstalevolume_types.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ import (
2626

2727
// RecoverStaleVolumeSpec defines the desired state of RecoverStaleVolume
2828
type RecoverStaleVolumeSpec struct {
29-
NoOfLogLines int64 `json:"noOfLogLines,omitempty"`
30-
Deployment []DeploymentData `json:"deploymentData,omitempty"`
29+
LogHistory int64 `json:"logHistory,omitempty"`
30+
Data []NamespacedDeploymentData `json:"data"`
3131
}
3232

33-
// DeploymentData ...
34-
type DeploymentData struct {
35-
DeploymentName string `json:"deploymentName,omitempty"`
36-
DeploymentNamespace string `json:"deploymentNamespace,omitempty"`
33+
// NamespacedDeploymentData ...
34+
type NamespacedDeploymentData struct {
35+
Namespace string `json:"namespace"`
36+
Deployments []string `json:"deployments,omitempty"`
3737
}
3838

3939
// RecoverStaleVolumeStatus defines the observed state of RecoverStaleVolume

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 26 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/objectdriver.csi.ibm.com_recoverstalevolumes.yaml

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,25 @@ spec:
4040
spec:
4141
description: RecoverStaleVolumeSpec defines the desired state of RecoverStaleVolume
4242
properties:
43-
deploymentData:
43+
data:
4444
items:
45-
description: DeploymentData ...
45+
description: NamespacedDeploymentData ...
4646
properties:
47-
deploymentName:
48-
type: string
49-
deploymentNamespace:
47+
deployments:
48+
items:
49+
type: string
50+
type: array
51+
namespace:
5052
type: string
53+
required:
54+
- namespace
5155
type: object
5256
type: array
53-
noOfLogLines:
57+
logHistory:
5458
format: int64
5559
type: integer
60+
required:
61+
- data
5662
type: object
5763
status:
5864
description: RecoverStaleVolumeStatus defines the observed state of RecoverStaleVolume

config/default/kustomization.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Adds namespace to all resources.
2-
namespace: ibm-object-csi-operator-system
2+
namespace: ibm-object-csi-operator
33

44
# Value of this field is prepended to the
55
# names of all resources, e.g. a deployment named

config/samples/csi_v1alpha1_ibmobjectcsi.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ apiVersion: objectdriver.csi.ibm.com/v1alpha1
22
kind: IBMObjectCSI
33
metadata:
44
name: ibm-object-csi
5-
namespace: ibm-object-csi-operator-system
5+
namespace: ibm-object-csi-operator
66
labels:
77
app.kubernetes.io/name: ibm-object-csi
88
app.kubernetes.io/instance: ibm-object-csi

config/samples/csi_v1alpha1_recoverstalevolume.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ metadata:
55
app.kubernetes.io/name: recoverstalevolume
66
app.kubernetes.io/instance: recoverstalevolume-sample
77
name: recoverstalevolume-sample
8-
namespace: ibm-object-csi-operator-system
8+
namespace: ibm-object-csi-operator
99
spec:
10-
noOfLogLines: 200
11-
deploymentData:
12-
- deploymentName: cos-csi-app-deployment
13-
deploymentNamespace: default
10+
logHistory: 200
11+
data:
12+
- namespace: default
13+
deployments: []

controllers/constants/constants.go

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
// Package constants ...
22
package constants
33

4-
import "fmt"
4+
import (
5+
"fmt"
6+
"time"
7+
)
58

69
const (
710
APIGroup = "objectdriver.csi.ibm.com"
811

9-
APIVersion = "v1"
10-
CSIOperatorName = "ibm-object-csi-driver-operator"
11-
CSIDriverName = "ibm-object-csi-driver"
12-
DriverName = "cos.s3.csi.ibm.io"
12+
APIVersion = "v1"
13+
CSIOperatorName = "ibm-object-csi-driver-operator"
14+
CSIOperatorNamespace = "ibm-object-csi-operator"
15+
CSIDriverName = "ibm-object-csi-driver"
16+
DriverName = "cos.s3.csi.ibm.io"
1317

1418
RbacAuthorizationAPIGroup = "rbac.authorization.k8s.io"
1519
SecurityOpenshiftAPIGroup = "security.openshift.io"
@@ -73,10 +77,18 @@ const (
7377
ObjectCSIDriverOperatorDeployNS = "ibm-object-csi-operator-system"
7478
ObjectCSIDriver = "ibm-object-csi"
7579

76-
RcloneRetainStorageClass = "ibm-object-storage-rclone-retain-sc"
77-
RcloneStorageClass = "ibm-object-storage-rclone-sc"
78-
S3fsRetainStorageClass = "ibm-object-storage-s3fs-retain-sc"
79-
S3fsStorageClass = "ibm-object-storage-s3fs-sc"
80+
StorageClassPrefix = "ibm-object-storage-"
81+
StorageClassSuffix = "-sc"
82+
83+
RcloneRetainStorageClass = StorageClassPrefix + "rclone-retain" + StorageClassSuffix
84+
RcloneStorageClass = StorageClassPrefix + "rclone" + StorageClassSuffix
85+
S3fsRetainStorageClass = StorageClassPrefix + "s3fs-retain" + StorageClassSuffix
86+
S3fsStorageClass = StorageClassPrefix + "s3fs" + StorageClassSuffix
87+
88+
DefaultLogTailLines = 300
89+
DefaultNamespace = "default"
90+
ReconcilationTime = 5 * time.Minute
91+
TransportEndpointError = "transport endpoint is not connected"
8092
)
8193

8294
var CommonCSIResourceLabels = map[string]string{
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package crutils
2+
3+
import (
4+
"context"
5+
6+
appsv1 "k8s.io/api/apps/v1"
7+
corev1 "k8s.io/api/core/v1"
8+
"k8s.io/apimachinery/pkg/types"
9+
"sigs.k8s.io/controller-runtime/pkg/client"
10+
)
11+
12+
type K8sResourceOps struct {
13+
client.Client
14+
Ctx context.Context
15+
Namespace string
16+
}
17+
18+
func (op *K8sResourceOps) GetDeployment(name string) (*appsv1.Deployment, error) {
19+
deployment := &appsv1.Deployment{}
20+
err := op.Get(op.Ctx, types.NamespacedName{Name: name, Namespace: op.Namespace}, deployment)
21+
return deployment, err
22+
}
23+
24+
func (op *K8sResourceOps) ListDeployment() (*appsv1.DeploymentList, error) {
25+
var listOptions = &client.ListOptions{Namespace: op.Namespace}
26+
deploymentList := &appsv1.DeploymentList{}
27+
err := op.List(op.Ctx, deploymentList, listOptions)
28+
return deploymentList, err
29+
}
30+
31+
func (op *K8sResourceOps) DeletePod(pod *corev1.Pod) error {
32+
var zero int64
33+
var deleteOptions = &client.DeleteOptions{GracePeriodSeconds: &zero}
34+
err := op.Delete(op.Ctx, pod, deleteOptions)
35+
return err
36+
}
37+
38+
func (op *K8sResourceOps) ListPod() (*corev1.PodList, error) {
39+
var listOptions = &client.ListOptions{Namespace: op.Namespace}
40+
podList := &corev1.PodList{}
41+
err := op.List(op.Ctx, podList, listOptions)
42+
return podList, err
43+
}
44+
45+
func (op *K8sResourceOps) ListPVC() (*corev1.PersistentVolumeClaimList, error) {
46+
var listOptions = &client.ListOptions{Namespace: op.Namespace}
47+
pvcList := &corev1.PersistentVolumeClaimList{}
48+
err := op.List(op.Ctx, pvcList, listOptions)
49+
return pvcList, err
50+
}

controllers/logParser.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,15 @@ func parseLogs(nodePodLogs string) map[string]string {
5353
if len(matches) == 2 {
5454
mapContent := matches[1]
5555

56-
getVolumeID := regexp.MustCompile("VolumeId:\\S+").FindStringSubmatch(mapContent) //nolint:gosimple
57-
volumeID := strings.Split(getVolumeID[0], ":")[1]
56+
getVolumeID := regexp.MustCompile(`VolumeId:\S+`).FindStringSubmatch(mapContent)
57+
if len(getVolumeID) != 0 {
58+
volumeID := strings.Split(getVolumeID[0], ":")[1]
5859

59-
getErrMsg := strings.ReplaceAll(mapContent, getVolumeID[0], "")
60-
errMsg := strings.Split(getErrMsg, ":")[1]
60+
getErrMsg := strings.ReplaceAll(mapContent, getVolumeID[0], "")
61+
errMsg := strings.Split(getErrMsg, ":")[1]
6162

62-
volumesStats[volumeID] = errMsg
63+
volumesStats[volumeID] = errMsg
64+
}
6365
}
6466
}
6567
}

0 commit comments

Comments
 (0)