Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,24 @@ const (
IndependentNonPersistent = "independent_nonpersistent"
// Changes to virtual disk are made to a redo log and discarded at power off.
NonPersistent = "nonpersistent"

// This section defines the different conditions that CnsNodeVMBatchAttachment CR can take.
// ConditionReady reflects the overall status of the CR.
ConditionReady = "Ready"
// ConditionAttached reflects whether the given volume was attached successfully.
ConditionAttached = "VolumeAttached"
// ConditionDetached reflects whether the given volume was detached successfully.
ConditionDetached = "VolumeDetached"

// This section defines the different reasons for different conditions in the CnsNodeVMBatchAttachment CR.
// ReasonAttachFailed reflects that the volume failed to get attached.
// In case of successful attachment, reason is set to True.
ReasonAttachFailed = "AttachFailed"
// ReasonDetachFailed reflects that the volume failed to get detached.
// In case of successful detach, the volume's entry is removed from the CR.
ReasonDetachFailed = "DetachFailed"
// ReasonFailed reflects that the CR instance is not yet ready.
ReasonFailed = "Failed"
)

// SharingMode is the sharing mode of the virtual disk.
Expand Down Expand Up @@ -100,12 +118,15 @@ type PersistentVolumeClaimSpec struct {
// CnsNodeVMBatchAttachmentStatus defines the observed state of CnsNodeVMBatchAttachment
// +k8s:openapi-gen=true
type CnsNodeVMBatchAttachmentStatus struct {
// Error is the overall error status for the instance.
Error string `json:"error,omitempty"`
// +optional
// +listType=map
// +listMapKey=name
// VolumeStatus reflects the status for each volume.
VolumeStatus []VolumeStatus `json:"volumes,omitempty"`
// +optional

// Conditions describes any conditions associated with this CnsNodeVMBatchAttachment instance.
Conditions []metav1.Condition `json:"conditions,omitempty"`
}

type VolumeStatus struct {
Expand All @@ -118,17 +139,18 @@ type VolumeStatus struct {
type PersistentVolumeClaimStatus struct {
// ClaimName is the PVC name.
ClaimName string `json:"claimName"`
// Attached indicates the attach status of a PVC.
// If volume is not attached, Attached will be set to false.
// If volume is attached, Attached will be set to true.
// If volume is detached successfully, its entry will be removed from VolumeStatus.
Attached bool `json:"attached"`
// Error indicates the error which may have occurred during attach/detach.
Error string `json:"error,omitempty"`
// +optional

// CnsVolumeID is the volume ID for the PVC.
CnsVolumeID string `json:"cnsVolumeId,omitempty"`
// +optional

// DiskUUID is the ID obtained when volume is attached to a VM.
DiskUUID string `json:"diskUUID,omitempty"`
// +optional

// Conditions describes any conditions associated with this volume.
Conditions []metav1.Condition `json:"conditions,omitempty"`
}

// +genclient
Expand Down Expand Up @@ -157,3 +179,19 @@ type CnsNodeVMBatchAttachmentList struct {
metav1.ListMeta `json:"metadata,omitempty"`
Items []CnsNodeVMBatchAttachment `json:"items"`
}

func (in *CnsNodeVMBatchAttachment) GetConditions() []metav1.Condition {
return in.Status.Conditions
}

func (in *CnsNodeVMBatchAttachment) SetConditions(conditions []metav1.Condition) {
in.Status.Conditions = conditions
}

func (p *PersistentVolumeClaimStatus) GetConditions() []metav1.Condition {
return p.Conditions
}

func (p *PersistentVolumeClaimStatus) SetConditions(conditions []metav1.Condition) {
p.Conditions = conditions
}
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,77 @@ spec:
description: CnsNodeVMBatchAttachmentStatus defines the observed state
of CnsNodeVMBatchAttachment
properties:
error:
description: Error is the overall error status for the instance.
type: string
conditions:
description: Conditions describes any conditions associated with this
CnsNodeVMBatchAttachment instance.
items:
description: "Condition contains details for one aspect of the current
state of this API Resource.\n---\nThis struct is intended for
direct use as an array at the field path .status.conditions. For
example,\n\n\n\ttype FooStatus struct{\n\t // Represents the
observations of a foo's current state.\n\t // Known .status.conditions.type
are: \"Available\", \"Progressing\", and \"Degraded\"\n\t //
+patchMergeKey=type\n\t // +patchStrategy=merge\n\t // +listType=map\n\t
\ // +listMapKey=type\n\t Conditions []metav1.Condition `json:\"conditions,omitempty\"
patchStrategy:\"merge\" patchMergeKey:\"type\" protobuf:\"bytes,1,rep,name=conditions\"`\n\n\n\t
\ // other fields\n\t}"
properties:
lastTransitionTime:
description: |-
lastTransitionTime is the last time the condition transitioned from one status to another.
This should be when the underlying condition changed. If that is not known, then using the time when the API field changed is acceptable.
format: date-time
type: string
message:
description: |-
message is a human readable message indicating details about the transition.
This may be an empty string.
maxLength: 32768
type: string
observedGeneration:
description: |-
observedGeneration represents the .metadata.generation that the condition was set based upon.
For instance, if .metadata.generation is currently 12, but the .status.conditions[x].observedGeneration is 9, the condition is out of date
with respect to the current state of the instance.
format: int64
minimum: 0
type: integer
reason:
description: |-
reason contains a programmatic identifier indicating the reason for the condition's last transition.
Producers of specific condition types may define expected values and meanings for this field,
and whether the values are considered a guaranteed API.
The value should be a CamelCase string.
This field may not be empty.
maxLength: 1024
minLength: 1
pattern: ^[A-Za-z]([A-Za-z0-9_,:]*[A-Za-z0-9_])?$
type: string
status:
description: status of the condition, one of True, False, Unknown.
enum:
- "True"
- "False"
- Unknown
type: string
type:
description: |-
type of condition in CamelCase or in foo.example.com/CamelCase.
---
Many .condition.type values are consistent across resources like Available, but because arbitrary conditions can be
useful (see .node.status.conditions), the ability to deconflict is important.
The regex it matches is (dns1123SubdomainFmt/)?(qualifiedNameFmt)
maxLength: 316
pattern: ^([a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*/)?(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])$
type: string
required:
- lastTransitionTime
- message
- reason
- status
- type
type: object
type: array
volumes:
description: VolumeStatus reflects the status for each volume.
items:
Expand All @@ -126,29 +194,91 @@ spec:
description: PersistentVolumeClaim contains details about the
volume's current state.
properties:
attached:
description: |-
Attached indicates the attach status of a PVC.
If volume is not attached, Attached will be set to false.
If volume is attached, Attached will be set to true.
If volume is detached successfully, its entry will be removed from VolumeStatus.
type: boolean
claimName:
description: ClaimName is the PVC name.
type: string
cnsVolumeId:
description: CnsVolumeID is the volume ID for the PVC.
type: string
conditions:
description: Conditions describes any conditions associated
with this volume.
items:
description: "Condition contains details for one aspect
of the current state of this API Resource.\n---\nThis
struct is intended for direct use as an array at the
field path .status.conditions. For example,\n\n\n\ttype
FooStatus struct{\n\t // Represents the observations
of a foo's current state.\n\t // Known .status.conditions.type
are: \"Available\", \"Progressing\", and \"Degraded\"\n\t
\ // +patchMergeKey=type\n\t // +patchStrategy=merge\n\t
\ // +listType=map\n\t // +listMapKey=type\n\t
\ Conditions []metav1.Condition `json:\"conditions,omitempty\"
patchStrategy:\"merge\" patchMergeKey:\"type\" protobuf:\"bytes,1,rep,name=conditions\"`\n\n\n\t
\ // other fields\n\t}"
properties:
lastTransitionTime:
description: |-
lastTransitionTime is the last time the condition transitioned from one status to another.
This should be when the underlying condition changed. If that is not known, then using the time when the API field changed is acceptable.
format: date-time
type: string
message:
description: |-
message is a human readable message indicating details about the transition.
This may be an empty string.
maxLength: 32768
type: string
observedGeneration:
description: |-
observedGeneration represents the .metadata.generation that the condition was set based upon.
For instance, if .metadata.generation is currently 12, but the .status.conditions[x].observedGeneration is 9, the condition is out of date
with respect to the current state of the instance.
format: int64
minimum: 0
type: integer
reason:
description: |-
reason contains a programmatic identifier indicating the reason for the condition's last transition.
Producers of specific condition types may define expected values and meanings for this field,
and whether the values are considered a guaranteed API.
The value should be a CamelCase string.
This field may not be empty.
maxLength: 1024
minLength: 1
pattern: ^[A-Za-z]([A-Za-z0-9_,:]*[A-Za-z0-9_])?$
type: string
status:
description: status of the condition, one of True,
False, Unknown.
enum:
- "True"
- "False"
- Unknown
type: string
type:
description: |-
type of condition in CamelCase or in foo.example.com/CamelCase.
---
Many .condition.type values are consistent across resources like Available, but because arbitrary conditions can be
useful (see .node.status.conditions), the ability to deconflict is important.
The regex it matches is (dns1123SubdomainFmt/)?(qualifiedNameFmt)
maxLength: 316
pattern: ^([a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*/)?(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])$
type: string
required:
- lastTransitionTime
- message
- reason
- status
- type
type: object
type: array
diskUUID:
description: DiskUUID is the ID obtained when volume is
attached to a VM.
type: string
error:
description: Error indicates the error which may have occurred
during attach/detach.
type: string
required:
- attached
- claimName
type: object
required:
Expand All @@ -170,4 +300,4 @@ status:
kind: ""
plural: ""
conditions: []
storedVersions: []
storedVersions: []
8 changes: 6 additions & 2 deletions pkg/common/cns-lib/volume/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -1304,8 +1304,10 @@ func (m *defaultManager) DetachVolume(ctx context.Context, vm *cnsvsphere.Virtua
}
}
}
return faultType, logger.LogNewErrorf(log, "failed to detach cns volume: %q from node vm: %+v. fault: %+v, opId: %q",
log.Errorf("failed to detach cns volume: %q from node vm: %+v. fault: %+v, opId: %q",
volumeID, vm, spew.Sdump(volumeOperationRes.Fault), taskInfo.ActivationId)
return faultType, fmt.Errorf("failed to detach cns volume: %q, Error: %s,",
volumeID, volumeOperationRes.Fault.LocalizedMessage)
}
log.Infof("DetachVolume: Volume detached successfully. volumeID: %q, vm: %q, opId: %q",
volumeID, vm.String(), taskInfo.ActivationId)
Expand Down Expand Up @@ -3492,8 +3494,10 @@ func compileBatchAttachTaskResult(ctx context.Context, result cnstypes.BaseCnsVo
// In case of failure, set faultType and error.
faultType := ExtractFaultTypeFromVolumeResponseResult(ctx, volumeOperationResult)
batchAttachResult.FaultType = faultType
msg := fmt.Sprintf("failed to batch attach cns volume: %q to node vm: %q. fault: %q. opId: %q",
log.Errorf("failed to attach cns volume: %q to node vm: %q. fault: %q. opId: %q",
volumeId, vm.String(), faultType, activationId)
msg := fmt.Sprintf("failed to attach cns volume: %q Error: %s",
volumeId, volumeOperationResult.Fault.LocalizedMessage)
batchAttachResult.Error = errors.New(msg)
log.Infof("Constructed batch attach result for volume %s with failure", volumeId)
return batchAttachResult, nil
Expand Down
Loading