Skip to content

Commit 6462d1f

Browse files
committed
chore: bump validator; satisfy ValidationRule interface
Signed-off-by: Tyler Gillson <tyler.gillson@gmail.com>
1 parent 6cd6d9c commit 6462d1f

File tree

5 files changed

+25
-38
lines changed

5 files changed

+25
-38
lines changed

api/v1alpha1/azurevalidator_types.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package v1alpha1
1818

1919
import (
20+
"github.com/validator-labs/validator-plugin-azure/pkg/constants"
2021
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2122
)
2223

@@ -33,6 +34,11 @@ type AzureValidatorSpec struct {
3334
Auth AzureAuth `json:"auth" yaml:"auth"`
3435
}
3536

37+
// PluginCode returns the Azure validator's plugin code.
38+
func (s AzureValidatorSpec) PluginCode() string {
39+
return constants.PluginCode
40+
}
41+
3642
// ResultCount returns the number of validation results expected for an AzureValidatorSpec.
3743
func (s AzureValidatorSpec) ResultCount() int {
3844
return len(s.RBACRules) + len(s.CommunityGalleryImageRules)
@@ -139,6 +145,16 @@ type AzureValidator struct {
139145
Status AzureValidatorStatus `json:"status,omitempty"`
140146
}
141147

148+
// PluginCode returns the Azure validator's plugin code.
149+
func (v AzureValidator) PluginCode() string {
150+
return v.Spec.PluginCode()
151+
}
152+
153+
// ResultCount returns the number of validation results expected for an AzureValidator.
154+
func (v AzureValidator) ResultCount() int {
155+
return v.Spec.ResultCount()
156+
}
157+
142158
//+kubebuilder:object:root=true
143159

144160
// AzureValidatorList contains a list of AzureValidator

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ require (
1010
github.com/go-logr/logr v1.4.2
1111
github.com/onsi/ginkgo/v2 v2.19.1
1212
github.com/onsi/gomega v1.34.1
13-
github.com/validator-labs/validator v0.1.0
13+
github.com/validator-labs/validator v0.1.1
1414
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56
1515
k8s.io/api v0.30.3
1616
k8s.io/apimachinery v0.30.3

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,8 @@ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO
155155
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
156156
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
157157
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
158-
github.com/validator-labs/validator v0.1.0 h1:GVekIT5sG+kcyUbT04qb/pURmd9eE6NNKnSR9yJ1sQk=
159-
github.com/validator-labs/validator v0.1.0/go.mod h1:OeJMHGKW3pWGkvKxHLN7HzjelSILJg2k8w3Z9SdML1g=
158+
github.com/validator-labs/validator v0.1.1 h1:BzUWeSAP5eGHX2oOulJWZxXr+Zz6Uh6ZqP5sYudnv3I=
159+
github.com/validator-labs/validator v0.1.1/go.mod h1:to8CMM+LlTcEzbqxVyHND9/uJO2+ORTFk9ovqVOnCU8=
160160
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
161161
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
162162
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=

internal/controller/azurevalidator_controller.go

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,12 @@ package controller
2020
import (
2121
"context"
2222
"errors"
23-
"fmt"
2423
"os"
2524
"time"
2625

2726
"github.com/go-logr/logr"
2827
corev1 "k8s.io/api/core/v1"
2928
apierrs "k8s.io/apimachinery/pkg/api/errors"
30-
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3129
"k8s.io/apimachinery/pkg/runtime"
3230
ktypes "k8s.io/apimachinery/pkg/types"
3331
"sigs.k8s.io/cluster-api/util/patch"
@@ -36,11 +34,9 @@ import (
3634

3735
"github.com/validator-labs/validator-plugin-azure/api/v1alpha1"
3836
"github.com/validator-labs/validator-plugin-azure/pkg/azure"
39-
"github.com/validator-labs/validator-plugin-azure/pkg/constants"
4037
utils "github.com/validator-labs/validator-plugin-azure/pkg/utils/azure"
4138
vapi "github.com/validator-labs/validator/api/v1alpha1"
4239
"github.com/validator-labs/validator/pkg/types"
43-
"github.com/validator-labs/validator/pkg/util"
4440
vres "github.com/validator-labs/validator/pkg/validationresult"
4541
)
4642

@@ -91,16 +87,16 @@ func (r *AzureValidatorReconciler) Reconcile(ctx context.Context, req ctrl.Reque
9187
return ctrl.Result{}, err
9288
}
9389
nn := ktypes.NamespacedName{
94-
Name: validationResultName(validator),
90+
Name: vres.Name(validator),
9591
Namespace: req.Namespace,
9692
}
9793
if err := r.Get(ctx, nn, vr); err == nil {
98-
vres.HandleExistingValidationResult(vr, r.Log)
94+
vres.HandleExisting(vr, r.Log)
9995
} else {
10096
if !apierrs.IsNotFound(err) {
10197
l.Error(err, "unexpected error getting ValidationResult")
10298
}
103-
if err := vres.HandleNewValidationResult(ctx, r.Client, p, buildValidationResult(validator), r.Log); err != nil {
99+
if err := vres.HandleNew(ctx, r.Client, p, vres.Build(validator), r.Log); err != nil {
104100
return ctrl.Result{}, err
105101
}
106102
return ctrl.Result{RequeueAfter: time.Millisecond}, nil
@@ -152,7 +148,7 @@ func (r *AzureValidatorReconciler) Reconcile(ctx context.Context, req ctrl.Reque
152148
}
153149

154150
// Patch the ValidationResult with the latest ValidationRuleResults
155-
if err := vres.SafeUpdateValidationResult(ctx, p, vr, resp, r.Log); err != nil {
151+
if err := vres.SafeUpdate(ctx, p, vr, resp, r.Log); err != nil {
156152
return ctrl.Result{}, err
157153
}
158154

@@ -185,29 +181,3 @@ func (r *AzureValidatorReconciler) SetupWithManager(mgr ctrl.Manager) error {
185181
For(&v1alpha1.AzureValidator{}).
186182
Complete(r)
187183
}
188-
189-
func buildValidationResult(validator *v1alpha1.AzureValidator) *vapi.ValidationResult {
190-
return &vapi.ValidationResult{
191-
ObjectMeta: metav1.ObjectMeta{
192-
Name: validationResultName(validator),
193-
Namespace: validator.Namespace,
194-
OwnerReferences: []metav1.OwnerReference{
195-
{
196-
APIVersion: validator.APIVersion,
197-
Kind: validator.Kind,
198-
Name: validator.Name,
199-
UID: validator.UID,
200-
Controller: util.Ptr(true),
201-
},
202-
},
203-
},
204-
Spec: vapi.ValidationResultSpec{
205-
Plugin: constants.PluginCode,
206-
ExpectedResults: validator.Spec.ResultCount(),
207-
},
208-
}
209-
}
210-
211-
func validationResultName(validator *v1alpha1.AzureValidator) string {
212-
return fmt.Sprintf("validator-plugin-azure-%s", validator.Name)
213-
}

internal/controller/azurevalidator_controller_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
. "github.com/onsi/gomega"
99
"github.com/validator-labs/validator-plugin-azure/api/v1alpha1"
1010
vapi "github.com/validator-labs/validator/api/v1alpha1"
11+
vres "github.com/validator-labs/validator/pkg/validationresult"
1112
corev1 "k8s.io/api/core/v1"
1213
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1314
"k8s.io/apimachinery/pkg/types"
@@ -159,7 +160,7 @@ var _ = Describe("AzureValidator controller", Ordered, func() {
159160
}
160161

161162
vr := &vapi.ValidationResult{}
162-
vrKey := types.NamespacedName{Name: validationResultName(val), Namespace: validatorNamespace}
163+
vrKey := types.NamespacedName{Name: vres.Name(val), Namespace: validatorNamespace}
163164

164165
valEmptySecretName := val.DeepCopy()
165166
valEmptySecretName.Name = fmt.Sprintf("%s-empty-secret-name", azureValidatorName)

0 commit comments

Comments
 (0)