Skip to content

Commit

Permalink
refactor: change devspace port; always use exponential backoff; tidy …
Browse files Browse the repository at this point in the history
…validation result helpers

Signed-off-by: Tyler Gillson <tyler.gillson@gmail.com>
  • Loading branch information
TylerGillson committed Nov 9, 2023
1 parent f9af283 commit c866429
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 16 deletions.
6 changes: 3 additions & 3 deletions devspace-start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ COLOR_CYAN="\033[0;36m"
COLOR_RESET="\033[0m"

RUN_CMD="go run ./cmd/main.go"
DEBUG_CMD="dlv debug ./cmd/main.go --listen=0.0.0.0:2343 --api-version=2 --output /tmp/__debug_bin --headless"
DEBUG_CMD="dlv debug ./cmd/main.go --listen=0.0.0.0:2342 --api-version=2 --output /tmp/__debug_bin --headless"

echo -e "${COLOR_CYAN}
____ ____
Expand All @@ -22,8 +22,8 @@ This is how you can work with it:
If you wish to run validator in the debug mode with delve, run:
\`${COLOR_CYAN}${DEBUG_CMD}${COLOR_RESET}\`
Wait until the \`${COLOR_CYAN}API server listening at: [::]:2343${COLOR_RESET}\` message appears
Start the \"Debug (localhost:2343)\" configuration in VSCode to connect your debugger session.
Wait until the \`${COLOR_CYAN}API server listening at: [::]:2342${COLOR_RESET}\` message appears
Start the \"Debug (localhost:2342)\" configuration in VSCode to connect your debugger session.
${COLOR_CYAN}Note:${COLOR_RESET} validator won't start until you connect with the debugger.
${COLOR_CYAN}Note:${COLOR_RESET} validator will be stopped once you detach your debugger session.
Expand Down
2 changes: 1 addition & 1 deletion devspace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ dev:
workDir: /workspace
command: ./devspace-start.sh
ports:
- port: "2343"
- port: "2342"
sync:
- path: .:/workspace
excludePaths:
Expand Down
6 changes: 3 additions & 3 deletions internal/controller/validationresult_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,14 @@ func (r *ValidationResultReconciler) Reconcile(ctx context.Context, req ctrl.Req
sinkConfigKey := types.NamespacedName{Namespace: r.Namespace, Name: vc.Spec.Sink.SecretName}
if err := r.Client.Get(ctx, sinkConfigKey, sinkSecret); err != nil {
r.Log.Error(err, "failed to fetch sink configuration secret")
return ctrl.Result{RequeueAfter: time.Second * 30}, err
return ctrl.Result{}, err
}
sinkConfig = sinkSecret.Data
}

if err := sink.Configure(*r.SinkClient, *vc, sinkConfig); err != nil {
r.Log.Error(err, "failed to configure sink")
return ctrl.Result{RequeueAfter: time.Second * 30}, err
return ctrl.Result{}, err
}

if err := sink.Emit(*vr); err != nil {
Expand All @@ -135,7 +135,7 @@ func (r *ValidationResultReconciler) Reconcile(ctx context.Context, req ctrl.Req
}
vr.ObjectMeta.Annotations[ValidationResultHash] = currHash
if err := r.Client.Update(ctx, vr); err != nil {
return ctrl.Result{RequeueAfter: time.Second * 30}, err
return ctrl.Result{}, err
}
}

Expand Down
2 changes: 1 addition & 1 deletion internal/controller/validatorconfig_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func (r *ValidatorConfigReconciler) Reconcile(ctx context.Context, req ctrl.Requ
// deploy/redeploy plugins as required
if err := r.redeployIfNeeded(ctx, vc); err != nil {
r.Log.V(0).Error(err, "ValidatorConfig plugin deployment failed", "namespace", vc.Namespace, "name", vc.Name)
return ctrl.Result{RequeueAfter: time.Second * 5}, err
return ctrl.Result{}, err
}

return ctrl.Result{RequeueAfter: time.Second * 30}, nil
Expand Down
13 changes: 5 additions & 8 deletions pkg/validationresult/validation_result.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
ktypes "k8s.io/apimachinery/pkg/types"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"

"github.com/spectrocloud-labs/validator/api/v1alpha1"
Expand All @@ -19,7 +18,7 @@ import (
)

// HandleExistingValidationResult processes a preexisting validation result for the active validator
func HandleExistingValidationResult(nn ktypes.NamespacedName, vr *v1alpha1.ValidationResult, l logr.Logger) (*ctrl.Result, error) {
func HandleExistingValidationResult(nn ktypes.NamespacedName, vr *v1alpha1.ValidationResult, l logr.Logger) {
switch vr.Status.State {

case v1alpha1.ValidationInProgress:
Expand All @@ -42,12 +41,10 @@ func HandleExistingValidationResult(nn ktypes.NamespacedName, vr *v1alpha1.Valid
// log validation success, continue to re-validate
l.V(0).Info("Previous validation succeeded. Re-validating.", "name", nn.Name, "namespace", nn.Namespace)
}

return nil, nil
}

// HandleNewValidationResult creates a new validation result for the active validator
func HandleNewValidationResult(c client.Client, plugin string, nn ktypes.NamespacedName, vr *v1alpha1.ValidationResult, l logr.Logger) (*ctrl.Result, error) {
func HandleNewValidationResult(c client.Client, plugin string, nn ktypes.NamespacedName, vr *v1alpha1.ValidationResult, l logr.Logger) error {

// Create the ValidationResult
vr.ObjectMeta = metav1.ObjectMeta{
Expand All @@ -59,7 +56,7 @@ func HandleNewValidationResult(c client.Client, plugin string, nn ktypes.Namespa
}
if err := c.Create(context.Background(), vr, &client.CreateOptions{}); err != nil {
l.V(0).Error(err, "failed to create ValidationResult", "name", nn.Name, "namespace", nn.Namespace)
return &ctrl.Result{}, err
return err
}

// Update the ValidationResult's status
Expand All @@ -68,10 +65,10 @@ func HandleNewValidationResult(c client.Client, plugin string, nn ktypes.Namespa
}
if err := c.Status().Update(context.Background(), vr); err != nil {
l.V(0).Error(err, "failed to update ValidationResult status", "name", nn.Name, "namespace", nn.Namespace)
return &ctrl.Result{}, err
return err
}

return nil, nil
return nil
}

// SafeUpdateValidationResult updates the overall validation result, ensuring
Expand Down

0 comments on commit c866429

Please sign in to comment.