Skip to content

Commit

Permalink
Minor name refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
cheina97 committed Sep 7, 2023
1 parent 1a60867 commit 5d6ee7a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 32 deletions.
34 changes: 17 additions & 17 deletions pkg/liqo-controller-manager/virtualnode-controller/condition.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,54 +23,54 @@ import (
virtualkubeletv1alpha1 "github.com/liqotech/liqo/apis/virtualkubelet/v1alpha1"
)

// VkConditionMap is a map of virtual node conditions.
type VkConditionMap map[virtualkubeletv1alpha1.VirtualNodeConditionType]VkCondition
// VnConditionMap is a map of virtual node conditions.
type VnConditionMap map[virtualkubeletv1alpha1.VirtualNodeConditionType]VnCondition

// VkCondition is a virtual node condition.
type VkCondition struct {
// VnCondition is a virtual node condition.
type VnCondition struct {
Status virtualkubeletv1alpha1.VirtualNodeConditionStatusType
Message string
}

// ForgeCondition forges a virtual node condition.
func ForgeCondition(
virtualNode *virtualkubeletv1alpha1.VirtualNode,
vkConditions VkConditionMap) (update bool) {
for nameCondition, vkCondition := range vkConditions {
vnConditions VnConditionMap) (update bool) {
for nameCondition, vnCondition := range vnConditions {
for i := range virtualNode.Status.Conditions {
if virtualNode.Status.Conditions[i].Type != nameCondition {
continue
}
if virtualNode.Status.Conditions[i].Status == vkCondition.Status {
if virtualNode.Status.Conditions[i].Status == vnCondition.Status {
return false
}
if (virtualNode.Status.Conditions[i].Status == virtualkubeletv1alpha1.RunningConditionStatusType) &&
(vkCondition.Status == virtualkubeletv1alpha1.CreatingConditionStatusType) {
(vnCondition.Status == virtualkubeletv1alpha1.CreatingConditionStatusType) {
return false
}
if (virtualNode.Status.Conditions[i].Status == virtualkubeletv1alpha1.NoneConditionStatusType) &&
(vkCondition.Status == virtualkubeletv1alpha1.DrainingConditionStatusType) {
(vnCondition.Status == virtualkubeletv1alpha1.DrainingConditionStatusType) {
return false
}
if (virtualNode.Status.Conditions[i].Status == virtualkubeletv1alpha1.NoneConditionStatusType) &&
(vkCondition.Status == virtualkubeletv1alpha1.DeletingConditionStatusType) {
(vnCondition.Status == virtualkubeletv1alpha1.DeletingConditionStatusType) {
return false
}
if (virtualNode.Status.Conditions[i].Status == virtualkubeletv1alpha1.DeletingConditionStatusType) &&
vkCondition.Status == virtualkubeletv1alpha1.DrainingConditionStatusType {
vnCondition.Status == virtualkubeletv1alpha1.DrainingConditionStatusType {
return false
}
virtualNode.Status.Conditions[i].Status = vkCondition.Status
virtualNode.Status.Conditions[i].Status = vnCondition.Status
virtualNode.Status.Conditions[i].LastTransitionTime = metav1.Now()
virtualNode.Status.Conditions[i].Message = vkCondition.Message
virtualNode.Status.Conditions[i].Message = vnCondition.Message
return true
}
virtualNode.Status.Conditions = append(virtualNode.Status.Conditions,
virtualkubeletv1alpha1.VirtualNodeCondition{
Type: nameCondition,
Status: vkCondition.Status,
Status: vnCondition.Status,
LastTransitionTime: metav1.Now(),
Message: vkCondition.Message,
Message: vnCondition.Message,
})
}
return true
Expand All @@ -79,9 +79,9 @@ func ForgeCondition(
// UpdateCondition updates the condition of the virtual node.
func UpdateCondition(ctx context.Context, cl client.Client,
virtualNode *virtualkubeletv1alpha1.VirtualNode,
vkConditions VkConditionMap,
vnConditions VnConditionMap,
) error {
if ForgeCondition(virtualNode, vkConditions) {
if ForgeCondition(virtualNode, vnConditions) {
if err := cl.Status().Update(ctx, virtualNode); err != nil {
return err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ func (dr *DeletionRoutine) handle(ctx context.Context, key string) error {
}
klog.Infof("Deletion routine started for virtual node %s", vn.Name)
if err := UpdateCondition(ctx, dr.vnr.Client, vn,
VkConditionMap{
virtualkubeletv1alpha1.NodeConditionType: VkCondition{
VnConditionMap{
virtualkubeletv1alpha1.NodeConditionType: VnCondition{
Status: virtualkubeletv1alpha1.DrainingConditionStatusType,
},
}); err != nil {
Expand Down Expand Up @@ -154,8 +154,8 @@ func (dr *DeletionRoutine) handle(ctx context.Context, key string) error {
// Node is being deleted, but the VirtualNode resource is not.
// The VirtualNode .Spec.CreateNode field is set to false.
if err := UpdateCondition(ctx, dr.vnr.Client, vn,
VkConditionMap{
virtualkubeletv1alpha1.NodeConditionType: VkCondition{
VnConditionMap{
virtualkubeletv1alpha1.NodeConditionType: VnCondition{
Status: virtualkubeletv1alpha1.NoneConditionStatusType,
},
}); err != nil {
Expand Down Expand Up @@ -183,8 +183,8 @@ func (dr *DeletionRoutine) deleteNode(ctx context.Context, node *corev1.Node, vn

if !vn.DeletionTimestamp.IsZero() {
if err := UpdateCondition(ctx, dr.vnr.Client, vn,
VkConditionMap{
virtualkubeletv1alpha1.VirtualKubeletConditionType: VkCondition{
VnConditionMap{
virtualkubeletv1alpha1.VirtualKubeletConditionType: VnCondition{
Status: virtualkubeletv1alpha1.DeletingConditionStatusType,
},
},
Expand All @@ -198,8 +198,8 @@ func (dr *DeletionRoutine) deleteNode(ctx context.Context, node *corev1.Node, vn
klog.Infof("VirtualKubelet deployment %s deleted", vn.Name)

if err := UpdateCondition(ctx, dr.vnr.Client, vn,
VkConditionMap{
virtualkubeletv1alpha1.NodeConditionType: VkCondition{
VnConditionMap{
virtualkubeletv1alpha1.NodeConditionType: VnCondition{
Status: virtualkubeletv1alpha1.DeletingConditionStatusType,
},
}); err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ func (r *VirtualNodeReconciler) ensureVirtualKubeletDeploymentPresence(
nodeStatusInitial = virtualkubeletv1alpha1.NoneConditionStatusType
}
if err := UpdateCondition(ctx, cl, virtualNode,
VkConditionMap{
virtualkubeletv1alpha1.VirtualKubeletConditionType: VkCondition{
VnConditionMap{
virtualkubeletv1alpha1.VirtualKubeletConditionType: VnCondition{
Status: virtualkubeletv1alpha1.CreatingConditionStatusType,
},
virtualkubeletv1alpha1.NodeConditionType: VkCondition{Status: nodeStatusInitial},
virtualkubeletv1alpha1.NodeConditionType: VnCondition{Status: nodeStatusInitial},
},
); err != nil {
return err
Expand Down Expand Up @@ -104,17 +104,17 @@ func (r *VirtualNodeReconciler) ensureVirtualKubeletDeploymentPresence(
}

if err := UpdateCondition(ctx, cl, virtualNode,
VkConditionMap{
virtualkubeletv1alpha1.VirtualKubeletConditionType: VkCondition{
VnConditionMap{
virtualkubeletv1alpha1.VirtualKubeletConditionType: VnCondition{
Status: virtualkubeletv1alpha1.RunningConditionStatusType,
},
}); err != nil {
return err
}
if *virtualNode.Spec.CreateNode {
return UpdateCondition(ctx, cl, virtualNode,
VkConditionMap{
virtualkubeletv1alpha1.NodeConditionType: VkCondition{
VnConditionMap{
virtualkubeletv1alpha1.NodeConditionType: VnCondition{
Status: virtualkubeletv1alpha1.RunningConditionStatusType,
},
})
Expand Down

0 comments on commit 5d6ee7a

Please sign in to comment.