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 @@ -77,3 +77,126 @@ statusItems:
resourceTemplateGeneration: 1
operation: AggregateStatus
output:
status:
replicas: 4
readyReplicas: 4
availableReplicas: 4
updatedReplicas: 4
updatedReadyReplicas: 4
expectedUpdatedReplicas: 4
observedGeneration: 1



# case2. CloneSet with partially ready replicas

name: "CloneSet with partially ready replicas"
description: "AggregateStatus when some replicas are not ready"
desiredObj:
apiVersion: apps.kruise.io/v1alpha1
kind: CloneSet
metadata:
name: sample
namespace: test-cloneset
generation: 2
spec:
replicas: 4
statusItems:
- applied: true
clusterName: member1
status:
replicas: 2
readyReplicas: 1
availableReplicas: 1
updatedReplicas: 2
updatedReadyReplicas: 1
expectedUpdatedReplicas: 2
generation: 2
observedGeneration: 2
resourceTemplateGeneration: 2
- applied: true
clusterName: member2
status:
replicas: 2
readyReplicas: 2
availableReplicas: 2
updatedReplicas: 2
updatedReadyReplicas: 2
expectedUpdatedReplicas: 2
generation: 2
observedGeneration: 2
resourceTemplateGeneration: 2
operation: AggregateStatus
output:
status:
replicas: 4
readyReplicas: 3
availableReplicas: 3
updatedReplicas: 4
updatedReadyReplicas: 3
expectedUpdatedReplicas: 4
observedGeneration: 2


# case3. CloneSet with mixed observed generations

name: "CloneSet with mixed observed generations"
description: "AggregateStatus should not update observedGeneration if any member is stale"
desiredObj:
apiVersion: apps.kruise.io/v1alpha1
kind: CloneSet
metadata:
name: sample
namespace: test-cloneset
generation: 3
status:
observedGeneration: 2
statusItems:
- applied: true
clusterName: member1
status:
replicas: 2
readyReplicas: 2
generation: 3
observedGeneration: 3
resourceTemplateGeneration: 3
- applied: true
clusterName: member2
status:
replicas: 2
readyReplicas: 2
generation: 3
observedGeneration: 2
resourceTemplateGeneration: 3
operation: AggregateStatus
output:
status:
replicas: 4
readyReplicas: 4
observedGeneration: 2



# case4. CloneSet with no status items

name: "CloneSet with no status items"
description: "AggregateStatus when CloneSet is not propagated"
desiredObj:
apiVersion: apps.kruise.io/v1alpha1
kind: CloneSet
metadata:
name: sample
namespace: test-cloneset
generation: 1
operation: AggregateStatus
output:
status:
replicas: 0
readyReplicas: 0
availableReplicas: 0
updatedReplicas: 0
updatedReadyReplicas: 0
expectedUpdatedReplicas: 0
observedGeneration: 1


Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,12 @@ desiredObj:
key: lower
operation: InterpretDependency
output:
dependencies:
- apiVersion: v1
kind: ConfigMap
namespace: test-cloneset
name: my-sample-config
- apiVersion: v1
kind: ConfigMap
namespace: test-cloneset
name: mysql-config
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,92 @@ observedObj:
updatedReplicas: 2
operation: InterpretHealth
output:
healthy: true


# case2. CloneSet health when observedGeneration mismatches generation

name: "CloneSet health when observedGeneration mismatches generation"
description: "Health should be false when observedGeneration != generation"
observedObj:
apiVersion: apps.kruise.io/v1alpha1
kind: CloneSet
metadata:
annotations:
resourcetemplate.karmada.io/generation: "1"
name: sample
namespace: test-cloneset
generation: 2
spec:
replicas: 2
template:
spec:
containers:
- name: nginx
image: nginx:alpine
status:
observedGeneration: 1
updatedReplicas: 2
availableReplicas: 2
operation: InterpretHealth
output:
healthy: false

# case3. CloneSet health when updatedReplicas less than desired replicas


name: "CloneSet health when updatedReplicas less than desired replicas"
description: "Health should be false when updatedReplicas < spec.replicas"
observedObj:
apiVersion: apps.kruise.io/v1alpha1
kind: CloneSet
metadata:
annotations:
resourcetemplate.karmada.io/generation: "1"
name: sample
namespace: test-cloneset
generation: 1
spec:
replicas: 3
template:
spec:
containers:
- name: nginx
image: nginx:alpine
status:
observedGeneration: 1
updatedReplicas: 2
availableReplicas: 2
operation: InterpretHealth
output:
healthy: false


# case4. CloneSet health when availableReplicas less than updatedReplicas


name: "CloneSet health when availableReplicas less than updatedReplicas"
description: "Health should be false when availableReplicas < updatedReplicas"
observedObj:
apiVersion: apps.kruise.io/v1alpha1
kind: CloneSet
metadata:
annotations:
resourcetemplate.karmada.io/generation: "1"
name: sample
namespace: test-cloneset
generation: 1
spec:
replicas: 2
template:
spec:
containers:
- name: nginx
image: nginx:alpine
status:
observedGeneration: 1
updatedReplicas: 2
availableReplicas: 1
operation: InterpretHealth
output:
healthy: false
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,6 @@ desiredObj:
name: mysql-config
key: lower
operation: InterpretReplica

output:
replica: 4
Comment on lines +47 to +48

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

While this test correctly validates the replica count, it could be more comprehensive. The GetReplicas Lua function in customizations.yaml for CloneSet returns both replica and requirement. This test only validates the replica.

To improve test coverage, please consider also validating the requirement output. This would ensure that kube.accuratePodRequirements(obj.spec.template) is correctly interpreting fields like affinity and tolerations from the CloneSet's pod template.

Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,16 @@ observedObj:
updatedReplicas: 2
operation: InterpretStatus
output:
status:
availableReplicas: 2
currentRevision: sample-59df6bd888
expectedUpdatedReplicas: 2
generation: 1
labelSelector: app=sample,test=cloneset
observedGeneration: 1
readyReplicas: 2
replicas: 2
resourceTemplateGeneration: 1
updateRevision: sample-59df6bd888
updatedReadyReplicas: 2
updatedReplicas: 2
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,5 @@ desiredObj:
inputReplicas: 1
operation: ReviseReplica
output:
spec:
replicas: 1