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

Fixes Label-Selector, Pod Template label updates and TLS changes for client and peer communication #883

Merged
merged 2 commits into from
Oct 23, 2024
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
8 changes: 6 additions & 2 deletions api/v1alpha1/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,8 @@ const (
LastOperationStateSucceeded LastOperationState = "Succeeded"
// LastOperationStateError indicates that an operation is completed with errors and will be retried.
LastOperationStateError LastOperationState = "Error"
// LastOperationStateRequeue indicates that an operation is not completed and either due to an error or unfulfilled conditions will be retried.
LastOperationStateRequeue LastOperationState = "Requeue"
)

// LastOperation holds the information on the last operation done on the Etcd resource.
Expand Down Expand Up @@ -486,13 +488,15 @@ func (e *Etcd) IsReconciliationInProgress() bool {
return e.Status.LastOperation != nil &&
e.Status.LastOperation.Type == LastOperationTypeReconcile &&
(e.Status.LastOperation.State == LastOperationStateProcessing ||
e.Status.LastOperation.State == LastOperationStateError)
e.Status.LastOperation.State == LastOperationStateError ||
e.Status.LastOperation.State == LastOperationStateRequeue)
}

// IsDeletionInProgress returns true if the Etcd resource is currently being reconciled, else returns false.
func (e *Etcd) IsDeletionInProgress() bool {
return e.Status.LastOperation != nil &&
e.Status.LastOperation.Type == LastOperationTypeDelete &&
(e.Status.LastOperation.State == LastOperationStateProcessing ||
e.Status.LastOperation.State == LastOperationStateError)
e.Status.LastOperation.State == LastOperationStateError ||
e.Status.LastOperation.State == LastOperationStateRequeue)
}
6 changes: 3 additions & 3 deletions internal/component/clientservice/clientservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (r _resource) GetExistingResourceNames(ctx component.OperatorContext, etcdO
}
return resourceNames, druiderr.WrapError(err,
ErrGetClientService,
"GetExistingResourceNames",
component.OperationGetExistingResourceNames,
fmt.Sprintf("Error getting client service: %v for etcd: %v", svcObjectKey, druidv1alpha1.GetNamespaceName(etcdObjMeta)))
}
if metav1.IsControlledBy(objMeta, &etcdObjMeta) {
Expand All @@ -77,7 +77,7 @@ func (r _resource) Sync(ctx component.OperatorContext, etcd *druidv1alpha1.Etcd)
if err != nil {
return druiderr.WrapError(err,
ErrSyncClientService,
"Sync",
component.OperationSync,
fmt.Sprintf("Error during create or update of client service: %v for etcd: %v", objectKey, druidv1alpha1.GetNamespaceName(etcd.ObjectMeta)),
)
}
Expand All @@ -97,7 +97,7 @@ func (r _resource) TriggerDelete(ctx component.OperatorContext, etcdObjMeta meta
return druiderr.WrapError(
err,
ErrDeleteClientService,
"TriggerDelete",
component.OperationTriggerDelete,
"Failed to delete client service",
)
}
Expand Down
8 changes: 4 additions & 4 deletions internal/component/clientservice/clientservice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func TestGetExistingResourceNames(t *testing.T) {
expectedErr: &druiderr.DruidError{
Code: ErrGetClientService,
Cause: testutils.TestAPIInternalErr,
Operation: "GetExistingResourceNames",
Operation: component.OperationGetExistingResourceNames,
},
},
}
Expand Down Expand Up @@ -106,7 +106,7 @@ func TestSyncWhenNoServiceExists(t *testing.T) {
expectedErr: &druiderr.DruidError{
Code: ErrSyncClientService,
Cause: testutils.TestAPIInternalErr,
Operation: "Sync",
Operation: component.OperationSync,
},
},
}
Expand Down Expand Up @@ -159,7 +159,7 @@ func TestSyncWhenServiceExists(t *testing.T) {
expectedError: &druiderr.DruidError{
Code: ErrSyncClientService,
Cause: testutils.TestAPIInternalErr,
Operation: "Sync",
Operation: component.OperationSync,
},
},
}
Expand Down Expand Up @@ -211,7 +211,7 @@ func TestTriggerDelete(t *testing.T) {
expectedErr: &druiderr.DruidError{
Code: ErrDeleteClientService,
Cause: testutils.TestAPIInternalErr,
Operation: "TriggerDelete",
Operation: component.OperationTriggerDelete,
},
deleteErr: testutils.TestAPIInternalErr,
},
Expand Down
12 changes: 7 additions & 5 deletions internal/component/configmap/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (r _resource) GetExistingResourceNames(ctx component.OperatorContext, etcdO
}
return nil, druiderr.WrapError(err,
ErrGetConfigMap,
"GetExistingResourceNames",
component.OperationGetExistingResourceNames,
fmt.Sprintf("Error getting ConfigMap: %v for etcd: %v", objKey, druidv1alpha1.GetNamespaceName(etcdObjMeta)))
}
if metav1.IsControlledBy(objMeta, &etcdObjMeta) {
Expand All @@ -65,7 +65,9 @@ func (r _resource) GetExistingResourceNames(ctx component.OperatorContext, etcdO
}

// PreSync is a no-op for the configmap component.
func (r _resource) PreSync(_ component.OperatorContext, _ *druidv1alpha1.Etcd) error { return nil }
func (r _resource) PreSync(_ component.OperatorContext, _ *druidv1alpha1.Etcd) error {
return nil
}

// Sync creates or updates the configmap for the given Etcd.
func (r _resource) Sync(ctx component.OperatorContext, etcd *druidv1alpha1.Etcd) error {
Expand All @@ -76,14 +78,14 @@ func (r _resource) Sync(ctx component.OperatorContext, etcd *druidv1alpha1.Etcd)
if err != nil {
return druiderr.WrapError(err,
ErrSyncConfigMap,
"Sync",
component.OperationSync,
fmt.Sprintf("Error during create or update of configmap for etcd: %v", druidv1alpha1.GetNamespaceName(etcd.ObjectMeta)))
}
checkSum, err := computeCheckSum(cm)
if err != nil {
return druiderr.WrapError(err,
ErrSyncConfigMap,
"Sync",
component.OperationSync,
fmt.Sprintf("Error when computing CheckSum for configmap for etcd: %v", druidv1alpha1.GetNamespaceName(etcd.ObjectMeta)))
}
ctx.Data[common.CheckSumKeyConfigMap] = checkSum
Expand All @@ -103,7 +105,7 @@ func (r _resource) TriggerDelete(ctx component.OperatorContext, etcdObjMeta meta
return druiderr.WrapError(
err,
ErrDeleteConfigMap,
"TriggerDelete",
component.OperationTriggerDelete,
"Failed to delete configmap",
)
}
Expand Down
8 changes: 4 additions & 4 deletions internal/component/configmap/configmap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func TestGetExistingResourceNames(t *testing.T) {
expectedErr: &druiderr.DruidError{
Code: ErrGetConfigMap,
Cause: testutils.TestAPIInternalErr,
Operation: "GetExistingResourceNames",
Operation: component.OperationGetExistingResourceNames,
},
},
}
Expand Down Expand Up @@ -115,7 +115,7 @@ func TestSyncWhenNoConfigMapExists(t *testing.T) {
expectedErr: &druiderr.DruidError{
Code: ErrSyncConfigMap,
Cause: testutils.TestAPIInternalErr,
Operation: "Sync",
Operation: component.OperationSync,
},
},
}
Expand Down Expand Up @@ -211,7 +211,7 @@ func TestSyncWhenConfigMapExists(t *testing.T) {
expectedErr: &druiderr.DruidError{
Code: ErrSyncConfigMap,
Cause: testutils.TestAPIInternalErr,
Operation: "Sync",
Operation: component.OperationSync,
},
},
}
Expand Down Expand Up @@ -264,7 +264,7 @@ func TestTriggerDelete(t *testing.T) {
expectedErr: &druiderr.DruidError{
Code: ErrDeleteConfigMap,
Cause: testutils.TestAPIInternalErr,
Operation: "TriggerDelete",
Operation: component.OperationTriggerDelete,
},
},
}
Expand Down
6 changes: 3 additions & 3 deletions internal/component/memberlease/memberlease.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (r _resource) GetExistingResourceNames(ctx component.OperatorContext, etcdO
); err != nil {
return resourceNames, druiderr.WrapError(err,
ErrListMemberLease,
"GetExistingResourceNames",
component.OperationGetExistingResourceNames,
fmt.Sprintf("Error listing member leases for etcd: %v", druidv1alpha1.GetNamespaceName(etcdObjMeta)))
}
for _, lease := range objMetaList.Items {
Expand Down Expand Up @@ -98,7 +98,7 @@ func (r _resource) doCreateOrUpdate(ctx component.OperatorContext, etcd *druidv1
if err != nil {
return druiderr.WrapError(err,
ErrSyncMemberLease,
"Sync",
component.OperationSync,
fmt.Sprintf("Error syncing member lease: %v for etcd: %v", objKey, druidv1alpha1.GetNamespaceName(etcd.ObjectMeta)))
}
ctx.Logger.Info("triggered create or update of member lease", "objectKey", objKey, "operationResult", opResult)
Expand All @@ -114,7 +114,7 @@ func (r _resource) TriggerDelete(ctx component.OperatorContext, etcdObjMeta meta
client.MatchingLabels(getSelectorLabelsForAllMemberLeases(etcdObjMeta))); err != nil {
return druiderr.WrapError(err,
ErrDeleteMemberLease,
"TriggerDelete",
component.OperationTriggerDelete,
fmt.Sprintf("Failed to delete member leases for etcd: %v", druidv1alpha1.GetNamespaceName(etcdObjMeta)))
}
ctx.Logger.Info("deleted", "component", "member-leases")
Expand Down
8 changes: 4 additions & 4 deletions internal/component/memberlease/memberlease_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func TestGetExistingResourceNames(t *testing.T) {
expectedErr: &druiderr.DruidError{
Code: ErrListMemberLease,
Cause: testutils.TestAPIInternalErr,
Operation: "GetExistingResourceNames",
Operation: component.OperationGetExistingResourceNames,
},
},
}
Expand Down Expand Up @@ -135,7 +135,7 @@ func TestSync(t *testing.T) {
expectedErr: &druiderr.DruidError{
Code: ErrSyncMemberLease,
Cause: testutils.TestAPIInternalErr,
Operation: "Sync",
Operation: component.OperationSync,
},
},
{
Expand All @@ -146,7 +146,7 @@ func TestSync(t *testing.T) {
expectedErr: &druiderr.DruidError{
Code: ErrSyncMemberLease,
Cause: testutils.TestAPIInternalErr,
Operation: "Sync",
Operation: component.OperationSync,
},
},
}
Expand Down Expand Up @@ -229,7 +229,7 @@ func TestTriggerDelete(t *testing.T) {
expectedErr: &druiderr.DruidError{
Code: ErrDeleteMemberLease,
Cause: testutils.TestAPIInternalErr,
Operation: "TriggerDelete",
Operation: component.OperationTriggerDelete,
},
},
}
Expand Down
6 changes: 3 additions & 3 deletions internal/component/peerservice/peerservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (r _resource) GetExistingResourceNames(ctx component.OperatorContext, etcdO
}
return resourceNames, druiderr.WrapError(err,
ErrGetPeerService,
"GetExistingResourceNames",
component.OperationGetExistingResourceNames,
fmt.Sprintf("Error getting peer service: %s for etcd: %v", svcObjectKey.Name, druidv1alpha1.GetNamespaceName(etcdObjMeta)))
}
if metav1.IsControlledBy(objMeta, &etcdObjMeta) {
Expand All @@ -77,7 +77,7 @@ func (r _resource) Sync(ctx component.OperatorContext, etcd *druidv1alpha1.Etcd)
if err != nil {
return druiderr.WrapError(err,
ErrSyncPeerService,
"Sync",
component.OperationSync,
fmt.Sprintf("Error during create or update of peer service: %v for etcd: %v", objectKey, druidv1alpha1.GetNamespaceName(etcd.ObjectMeta)),
)
}
Expand All @@ -97,7 +97,7 @@ func (r _resource) TriggerDelete(ctx component.OperatorContext, etcdObjMeta meta
return druiderr.WrapError(
err,
ErrDeletePeerService,
"TriggerDelete",
component.OperationTriggerDelete,
fmt.Sprintf("Failed to delete peer service: %v for etcd: %v", objectKey, druidv1alpha1.GetNamespaceName(etcdObjMeta)),
)
}
Expand Down
8 changes: 4 additions & 4 deletions internal/component/peerservice/peerservice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func TestGetExistingResourceNames(t *testing.T) {
expectedErr: &druiderr.DruidError{
Code: ErrGetPeerService,
Cause: testutils.TestAPIInternalErr,
Operation: "GetExistingResourceNames",
Operation: component.OperationGetExistingResourceNames,
},
},
}
Expand Down Expand Up @@ -105,7 +105,7 @@ func TestSyncWhenNoServiceExists(t *testing.T) {
expectedError: &druiderr.DruidError{
Code: ErrSyncPeerService,
Cause: testutils.TestAPIInternalErr,
Operation: "Sync",
Operation: component.OperationSync,
},
},
}
Expand Down Expand Up @@ -155,7 +155,7 @@ func TestSyncWhenServiceExists(t *testing.T) {
expectedError: &druiderr.DruidError{
Code: ErrSyncPeerService,
Cause: testutils.TestAPIInternalErr,
Operation: "Sync",
Operation: component.OperationSync,
},
},
}
Expand Down Expand Up @@ -209,7 +209,7 @@ func TestPeerServiceTriggerDelete(t *testing.T) {
expectError: &druiderr.DruidError{
Code: ErrDeletePeerService,
Cause: deleteInternalErr,
Operation: "TriggerDelete",
Operation: component.OperationTriggerDelete,
},
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (r _resource) GetExistingResourceNames(ctx component.OperatorContext, etcdO
}
return resourceNames, druiderr.WrapError(err,
ErrGetPodDisruptionBudget,
"GetExistingResourceNames",
component.OperationGetExistingResourceNames,
fmt.Sprintf("Error getting PDB: %v for etcd: %v", objectKey, druidv1alpha1.GetNamespaceName(etcdObjMeta)))
}
if metav1.IsControlledBy(objMeta, &etcdObjMeta) {
Expand All @@ -83,7 +83,7 @@ func (r _resource) Sync(ctx component.OperatorContext, etcd *druidv1alpha1.Etcd)
if err != nil {
return druiderr.WrapError(err,
ErrSyncPodDisruptionBudget,
"Sync",
component.OperationSync,
fmt.Sprintf("Error during create or update of PDB: %v for etcd: %v", objectKey, druidv1alpha1.GetNamespaceName(etcd.ObjectMeta)),
)
}
Expand All @@ -98,7 +98,7 @@ func (r _resource) TriggerDelete(ctx component.OperatorContext, etcdObjMeta meta
if err := client.IgnoreNotFound(r.client.Delete(ctx, emptyPodDisruptionBudget(pdbObjectKey))); err != nil {
return druiderr.WrapError(err,
ErrDeletePodDisruptionBudget,
"TriggerDelete",
component.OperationTriggerDelete,
fmt.Sprintf("Failed to delete PDB: %v for etcd: %v", pdbObjectKey, druidv1alpha1.GetNamespaceName(etcdObjMeta)))
}
ctx.Logger.Info("deleted", "component", "pod-disruption-budget", "objectKey", pdbObjectKey)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func TestGetExistingResourceNames(t *testing.T) {
expectedErr: &druiderr.DruidError{
Code: ErrGetPodDisruptionBudget,
Cause: testutils.TestAPIInternalErr,
Operation: "GetExistingResourceNames",
Operation: component.OperationGetExistingResourceNames,
},
},
}
Expand Down Expand Up @@ -107,7 +107,7 @@ func TestSyncWhenNoPDBExists(t *testing.T) {
expectedErr: &druiderr.DruidError{
Code: ErrSyncPodDisruptionBudget,
Cause: testutils.TestAPIInternalErr,
Operation: "Sync",
Operation: component.OperationSync,
},
},
}
Expand Down Expand Up @@ -161,7 +161,7 @@ func TestSyncWhenPDBExists(t *testing.T) {
expectedErr: &druiderr.DruidError{
Code: ErrSyncPodDisruptionBudget,
Cause: testutils.TestAPIInternalErr,
Operation: "Sync",
Operation: component.OperationSync,
},
},
}
Expand Down Expand Up @@ -214,7 +214,7 @@ func TestTriggerDelete(t *testing.T) {
expectedErr: &druiderr.DruidError{
Code: ErrDeletePodDisruptionBudget,
Cause: testutils.TestAPIInternalErr,
Operation: "TriggerDelete",
Operation: component.OperationTriggerDelete,
},
},
}
Expand Down
6 changes: 3 additions & 3 deletions internal/component/role/role.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (r _resource) GetExistingResourceNames(ctx component.OperatorContext, etcdO
}
return resourceNames, druiderr.WrapError(err,
ErrGetRole,
"GetExistingResourceNames",
component.OperationGetExistingResourceNames,
fmt.Sprintf("Error getting role: %v for etcd: %v", objectKey, druidv1alpha1.GetNamespaceName(etcdObjMeta)))
}
if metav1.IsControlledBy(objMeta, &etcdObjMeta) {
Expand All @@ -76,7 +76,7 @@ func (r _resource) Sync(ctx component.OperatorContext, etcd *druidv1alpha1.Etcd)
if err != nil {
return druiderr.WrapError(err,
ErrSyncRole,
"Sync",
component.OperationSync,
fmt.Sprintf("Error during create or update of role %v for etcd: %v", objectKey, druidv1alpha1.GetNamespaceName(etcd.ObjectMeta)),
)
}
Expand All @@ -95,7 +95,7 @@ func (r _resource) TriggerDelete(ctx component.OperatorContext, etcdObjMeta meta
}
return druiderr.WrapError(err,
ErrDeleteRole,
"TriggerDelete",
component.OperationTriggerDelete,
fmt.Sprintf("Failed to delete role: %v for etcd: %v", objectKey, druidv1alpha1.GetNamespaceName(etcdObjMeta)),
)
}
Expand Down
Loading