Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to newer cass-operator version for new Task Status fields #1098

Merged
merged 2 commits into from
Oct 24, 2023
Merged
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ GOLANGCI_LINT ?= $(LOCALBIN)/golangci-lint # TODO Add linting to the GHA also
CERT_MANAGER_VERSION ?= v1.12.2
KUSTOMIZE_VERSION ?= v5.0.3
CONTROLLER_TOOLS_VERSION ?= v0.12.0
GOLINT_VERSION ?= 1.54.2
GOLINT_VERSION ?= 1.55.0

cert-manager: ## Install cert-manager to the cluster
kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/$(CERT_MANAGER_VERSION)/cert-manager.yaml
Expand Down
35 changes: 18 additions & 17 deletions apis/control/v1alpha1/k8ssandratask_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,13 @@
totalActive += dcStatus.Active
totalSucceeded += dcStatus.Succeeded
totalFailed += dcStatus.Failed
if getConditionStatus(dcStatus, cassapi.JobRunning) == corev1.ConditionTrue {
if getConditionStatus(dcStatus, cassapi.JobRunning) == metav1.ConditionTrue {
anyRunning = true
}
if getConditionStatus(dcStatus, cassapi.JobFailed) == corev1.ConditionTrue {
if getConditionStatus(dcStatus, cassapi.JobFailed) == metav1.ConditionTrue {
anyFailed = true
}
if getConditionStatus(dcStatus, cassapi.JobComplete) != corev1.ConditionTrue {
if getConditionStatus(dcStatus, cassapi.JobComplete) != metav1.ConditionTrue {
allComplete = false
}
}
Expand All @@ -137,15 +137,15 @@
t.SetCondition(cassapi.JobFailed, toConditionStatus(anyFailed))
if allComplete && len(t.Status.Datacenters) == expectedDcCount {
t.Status.CompletionTime = lastCompletionTime
t.SetCondition(cassapi.JobComplete, corev1.ConditionTrue)
t.SetCondition(cassapi.JobComplete, metav1.ConditionTrue)

Check warning on line 140 in apis/control/v1alpha1/k8ssandratask_types.go

View check run for this annotation

Codecov / codecov/patch

apis/control/v1alpha1/k8ssandratask_types.go#L140

Added line #L140 was not covered by tests
}
}

func (t *K8ssandraTask) SetCondition(condition cassapi.JobConditionType, status corev1.ConditionStatus) bool {
func (t *K8ssandraTask) SetCondition(condition cassapi.JobConditionType, status metav1.ConditionStatus) bool {
existing := false
for i := 0; i < len(t.Status.Conditions); i++ {
cond := t.Status.Conditions[i]
if cond.Type == condition {
if cond.Type == string(condition) {
if cond.Status == status {
// Already correct status
return false
Expand All @@ -159,8 +159,9 @@
}

if !existing {
cond := cassapi.JobCondition{
Type: condition,
cond := metav1.Condition{
Type: string(condition),
Reason: string(condition),
Status: status,
LastTransitionTime: metav1.Now(),
}
Expand All @@ -170,32 +171,32 @@
return true
}

func (t *K8ssandraTask) GetConditionStatus(conditionType cassapi.JobConditionType) corev1.ConditionStatus {
func (t *K8ssandraTask) GetConditionStatus(conditionType cassapi.JobConditionType) metav1.ConditionStatus {
for _, condition := range t.Status.Conditions {
if condition.Type == conditionType {
if condition.Type == string(conditionType) {
return condition.Status
}
}
return corev1.ConditionUnknown
return metav1.ConditionUnknown
}

func getConditionStatus(s cassapi.CassandraTaskStatus, conditionType cassapi.JobConditionType) corev1.ConditionStatus {
func getConditionStatus(s cassapi.CassandraTaskStatus, conditionType cassapi.JobConditionType) metav1.ConditionStatus {
for _, condition := range s.Conditions {
if condition.Type == conditionType {
if condition.Type == string(conditionType) {
return condition.Status
}
}
return corev1.ConditionUnknown
return metav1.ConditionUnknown
}

func init() {
SchemeBuilder.Register(&K8ssandraTask{}, &K8ssandraTaskList{})
}

// toConditionStatus converts a primitive boolean into a k8s ConditionStatus
func toConditionStatus(condition bool) corev1.ConditionStatus {
func toConditionStatus(condition bool) metav1.ConditionStatus {
if condition {
return corev1.ConditionTrue
return metav1.ConditionTrue
}
return corev1.ConditionFalse
return metav1.ConditionFalse

Check warning on line 201 in apis/control/v1alpha1/k8ssandratask_types.go

View check run for this annotation

Codecov / codecov/patch

apis/control/v1alpha1/k8ssandratask_types.go#L201

Added line #L201 was not covered by tests
}
33 changes: 16 additions & 17 deletions apis/control/v1alpha1/k8ssandratask_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ import (
"testing"
"time"

"github.com/k8ssandra/cass-operator/apis/control/v1alpha1"
controlapi "github.com/k8ssandra/cass-operator/apis/control/v1alpha1"
"github.com/stretchr/testify/assert"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand All @@ -15,7 +14,7 @@ func TestRefreshGlobalStatus(t *testing.T) {
dcMap := generateDatacenters()

kts := K8ssandraTaskStatus{
CassandraTaskStatus: v1alpha1.CassandraTaskStatus{},
CassandraTaskStatus: controlapi.CassandraTaskStatus{},
Datacenters: dcMap,
}
kt := K8ssandraTask{
Expand All @@ -26,14 +25,14 @@ func TestRefreshGlobalStatus(t *testing.T) {
assert.Equal(t, 1, kt.Status.Failed)
assert.Equal(t, 1, kt.Status.Succeeded)
assert.Equal(t, 0, kt.Status.StartTime.Compare(time.Date(2023, 6, 10, 10, 10, 10, 10, time.UTC)))
assert.Equal(t, v1.ConditionTrue, kt.GetConditionStatus(v1alpha1.JobRunning))
assert.Equal(t, v1.ConditionTrue, kt.GetConditionStatus(v1alpha1.JobFailed))
assert.Equal(t, metav1.ConditionTrue, kt.GetConditionStatus(controlapi.JobRunning))
assert.Equal(t, metav1.ConditionTrue, kt.GetConditionStatus(controlapi.JobFailed))
// the test data does not have a completion time, so it should be Unknown
assert.Equal(t, v1.ConditionUnknown, kt.GetConditionStatus(v1alpha1.JobComplete))
assert.Equal(t, metav1.ConditionUnknown, kt.GetConditionStatus(controlapi.JobComplete))
}

func generateDatacenters() map[string]v1alpha1.CassandraTaskStatus {
return map[string]v1alpha1.CassandraTaskStatus{
func generateDatacenters() map[string]controlapi.CassandraTaskStatus {
return map[string]controlapi.CassandraTaskStatus{
"dc1": {
StartTime: &metav1.Time{
Time: time.Date(2023, 6, 13, 13, 13, 13, 13, time.UTC),
Expand All @@ -44,10 +43,10 @@ func generateDatacenters() map[string]v1alpha1.CassandraTaskStatus {
Active: 1,
Succeeded: 1,
Failed: 0,
Conditions: []v1alpha1.JobCondition{
Conditions: []metav1.Condition{
{
Type: v1alpha1.JobComplete,
Status: v1.ConditionTrue,
Type: string(controlapi.JobComplete),
Status: metav1.ConditionTrue,
},
},
},
Expand All @@ -61,10 +60,10 @@ func generateDatacenters() map[string]v1alpha1.CassandraTaskStatus {
Active: 0,
Succeeded: 0,
Failed: 1,
Conditions: []v1alpha1.JobCondition{
Conditions: []metav1.Condition{
{
Type: v1alpha1.JobFailed,
Status: v1.ConditionTrue,
Type: string(controlapi.JobFailed),
Status: metav1.ConditionTrue,
},
},
},
Expand All @@ -76,10 +75,10 @@ func generateDatacenters() map[string]v1alpha1.CassandraTaskStatus {
Active: 1,
Succeeded: 0,
Failed: 0,
Conditions: []v1alpha1.JobCondition{
Conditions: []metav1.Condition{
{
Type: v1alpha1.JobRunning,
Status: v1.ConditionTrue,
Type: string(controlapi.JobRunning),
Status: metav1.ConditionTrue,
},
},
},
Expand Down
2 changes: 1 addition & 1 deletion config/cass-operator/cluster-scoped/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ components:
# This is required when a new feature of cass-operator is needed that is not yet released.
images:
- name: k8ssandra/cass-operator
newTag: v1.18.0-dev.34e2ae6-20231002
newTag: v1.18.0-dev.5189beb-20231020
2 changes: 1 addition & 1 deletion config/cass-operator/ns-scoped/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ components:
# This is required when a new feature of cass-operator is needed that is not yet released.
images:
- name: k8ssandra/cass-operator
newTag: v1.18.0-dev.34e2ae6-20231002
newTag: v1.18.0-dev.5189beb-20231020
Loading
Loading