-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NamespaceMap refactor and some util functions
- MappingPhase type now can be exported. - Add Enum validation for Phase field, in NamespaceMap status. - Add two util functions to get and update remote namespaces' conditions.
- Loading branch information
1 parent
cc05ac0
commit caec626
Showing
3 changed files
with
66 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package utils | ||
|
||
import ( | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
|
||
offv1alpha1 "github.com/liqotech/liqo/apis/offloading/v1alpha1" | ||
) | ||
|
||
// UpdateNamespaceOffloadingCondition -> if present update condition of that type, otherwise create a new one. | ||
func UpdateNamespaceOffloadingCondition(status *offv1alpha1.NamespaceOffloadingStatus, | ||
newCondition offv1alpha1.RemoteNamespaceCondition, clusterID string) bool { | ||
|
||
if status.RemoteNamespacesConditions == nil { | ||
status.RemoteNamespacesConditions = map[string]offv1alpha1.RemoteNamespaceConditions{} | ||
} | ||
|
||
oldCondition := GetNamespaceOffloadingCondition(status.RemoteNamespacesConditions[clusterID], newCondition.Type) | ||
|
||
if oldCondition == nil { | ||
newCondition.LastTransitionTime = metav1.Now() | ||
status.RemoteNamespacesConditions[clusterID] = append(status.RemoteNamespacesConditions[clusterID], | ||
newCondition) | ||
return true | ||
} | ||
|
||
if oldCondition.Status != newCondition.Status || | ||
oldCondition.Message != newCondition.Message || oldCondition.Reason != newCondition.Reason { | ||
if oldCondition.Status != newCondition.Status { | ||
oldCondition.LastTransitionTime = metav1.Now() | ||
} | ||
oldCondition.Status = newCondition.Status | ||
oldCondition.Reason = newCondition.Reason | ||
oldCondition.Message = newCondition.Message | ||
return true | ||
} | ||
|
||
return false | ||
} | ||
|
||
// GetNamespaceOffloadingCondition -> get the condition of a certain type if it is present | ||
func GetNamespaceOffloadingCondition(conditions []offv1alpha1.RemoteNamespaceCondition, | ||
conditionType offv1alpha1.RemoteNamespaceConditionType) *offv1alpha1.RemoteNamespaceCondition { | ||
for i := range conditions { | ||
if conditions[i].Type == conditionType { | ||
return &(conditions[i]) | ||
} | ||
} | ||
return nil | ||
} |