Skip to content

Commit

Permalink
Flush messages on successful reconcile
Browse files Browse the repository at this point in the history
  • Loading branch information
aiivashchenko committed May 16, 2022
1 parent 07ab648 commit 1f505ab
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions api/v1alpha1/subnet_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ func init() {
// PopulateStatus fills status subresource with default values
func (in *Subnet) PopulateStatus() {
in.Status.State = CProcessingSubnetState
in.Status.Message = ""

regionCount := len(in.Spec.Regions)
if regionCount == 0 {
Expand Down Expand Up @@ -176,6 +177,7 @@ func (in *Subnet) FillStatusFromCidr(cidr *CIDR) {
in.Status.Type = CIPv6SubnetType
}

in.Status.Message = ""
in.Status.Reserved = cidr.DeepCopy()
in.Status.Vacant = []CIDR{*cidr.DeepCopy()}
in.Status.PrefixBits = cidr.MaskOnes()
Expand Down
2 changes: 2 additions & 0 deletions controllers/ip_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ func (r *IPReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Re

if ip.Status.State == "" {
ip.Status.State = v1alpha1.CProcessingIPState
ip.Status.Message = ""
if err := r.Status().Update(ctx, ip); err != nil {
log.Error(err, "unable to update ip resource status", "name", req.NamespacedName, "currentStatus", ip.Status.State, "targetStatus", v1alpha1.CProcessingNetworkState)
return ctrl.Result{}, err
Expand Down Expand Up @@ -158,6 +159,7 @@ func (r *IPReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Re
}

ip.Status.State = v1alpha1.CFinishedIPState
ip.Status.Message = ""
ip.Status.Reserved = ipCidrToReserve.AsIPAddr()
if err := r.Status().Update(ctx, ip); err != nil {
log.Error(err, "unable to update ip status after ip reservation", "name", req.NamespacedName, "subnet name", subnetNamespacedName)
Expand Down
5 changes: 5 additions & 0 deletions controllers/network_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ func (r *NetworkReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
network.Status.Reserved == nil &&
network.Spec.Type != "" {
network.Status.State = machinev1alpha1.CProcessingNetworkState
network.Status.Message = ""
if err := r.Status().Update(ctx, network); err != nil {
log.Error(err, "unable to update network resource status", "name", req.NamespacedName, "currentStatus", network.Status.State, "targetStatus", machinev1alpha1.CProcessingNetworkState)
return ctrl.Result{}, err
Expand All @@ -125,6 +126,7 @@ func (r *NetworkReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct

if network.Status.State == "" {
network.Status.State = machinev1alpha1.CProcessingNetworkState
network.Status.Message = ""
if err := r.Status().Update(ctx, network); err != nil {
log.Error(err, "unable to update network resource status", "name", req.NamespacedName, "currentStatus", network.Status.State, "targetStatus", machinev1alpha1.CProcessingNetworkState)
return ctrl.Result{}, err
Expand All @@ -135,6 +137,7 @@ func (r *NetworkReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
if network.Spec.Type == "" {
log.Info("network does not specify type, nothing to do for now", "name", req.NamespacedName)
network.Status.State = machinev1alpha1.CFinishedNetworkState
network.Status.Message = ""
if err := r.Status().Update(ctx, network); err != nil {
log.Error(err, "unable to update network status", "name", req.NamespacedName)
return ctrl.Result{}, err
Expand Down Expand Up @@ -203,6 +206,7 @@ func (r *NetworkReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
r.EventRecorder.Eventf(network, v1.EventTypeNormal, CNetworkIDReservationSuccessReason, "ID %s for type %s reserved successfully", networkIdToReserve, network.Spec.Type)

network.Status.State = machinev1alpha1.CFinishedNetworkState
network.Status.Message = ""
network.Status.Reserved = networkIdToReserve
if err := r.Status().Update(ctx, network); err != nil {
log.Error(err, "unable to update network status", "name", req.NamespacedName)
Expand All @@ -225,6 +229,7 @@ func (r *NetworkReconciler) requeueFailedSubnets(ctx context.Context, log logr.L

for _, subnet := range subnets.Items {
subnet.Status.State = machinev1alpha1.CProcessingSubnetState
subnet.Status.Message = ""
if err := r.Status().Update(ctx, &subnet); err != nil {
log.Error(err, "unable to update top level subnet", "name", types.NamespacedName{Namespace: network.Namespace, Name: network.Name}, "subnet", subnet.Name)
return err
Expand Down
1 change: 1 addition & 0 deletions controllers/networkcounter_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ func (r *NetworkCounterReconciler) Reconcile(ctx context.Context, req ctrl.Reque

for _, network := range networks.Items {
network.Status.State = machinev1alpha1.CProcessingNetworkState
network.Status.Message = ""
if err := r.Status().Update(ctx, &network); err != nil {
log.Error(err, "unable to update network", "name", req.NamespacedName, "network", network.Name)
return ctrl.Result{}, err
Expand Down
2 changes: 2 additions & 0 deletions controllers/subnet_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,7 @@ func (r *SubnetReconciler) requeueFailedSubnets(ctx context.Context, log logr.Lo

for _, subnet := range subnets.Items {
subnet.Status.State = v1alpha1.CProcessingSubnetState
subnet.Status.Message = ""
if err := r.Status().Update(ctx, &subnet); err != nil {
log.Error(err, "unable to update child subnet", "name", types.NamespacedName{Namespace: subnet.Namespace, Name: subnet.Name}, "subnet", subnet.Name)
return err
Expand All @@ -446,6 +447,7 @@ func (r *SubnetReconciler) requeueFailedIPs(ctx context.Context, log logr.Logger

for _, ip := range ips.Items {
ip.Status.State = v1alpha1.CProcessingIPState
ip.Status.Message = ""
if err := r.Status().Update(ctx, &ip); err != nil {
log.Error(err, "unable to update child ips", "name", types.NamespacedName{Namespace: subnet.Namespace, Name: subnet.Name}, "subnet", subnet.Name)
return err
Expand Down

0 comments on commit 1f505ab

Please sign in to comment.