This is an automated email from the ASF dual-hosted git repository.
wilfred-s pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/yunikorn-k8shim.git
The following commit(s) were added to refs/heads/master by this push:
new f4a8c880 [YUNIKORN-3347] Enhanced config validation checks (#1063)
f4a8c880 is described below
commit f4a8c88048d82e18b5d831e1ffb292d9c383f516
Author: sidbroski <[email protected]>
AuthorDate: Thu Aug 20 19:25:22 2026 +1000
[YUNIKORN-3347] Enhanced config validation checks (#1063)
Maps the new checksum and checksumMatch fields from the scheduler
validate-conf response and log them after a successful config validation.
Closes: #1063
Signed-off-by: Wilfred Spiegelenburg <[email protected]>
---
pkg/admission/admission_controller.go | 9 ++++---
pkg/admission/admission_controller_test.go | 40 ++++++++++++++++++++++++++++++
2 files changed, 46 insertions(+), 3 deletions(-)
diff --git a/pkg/admission/admission_controller.go
b/pkg/admission/admission_controller.go
index 82ee5427..7e68efd1 100644
--- a/pkg/admission/admission_controller.go
+++ b/pkg/admission/admission_controller.go
@@ -71,8 +71,10 @@ type AdmissionController struct {
}
type ValidateConfResponse struct {
- Allowed bool `json:"allowed"`
- Reason string `json:"reason"`
+ Allowed bool `json:"allowed"`
+ Reason string `json:"reason"`
+ Checksum string `json:"checksum"`
+ ChecksumMatch bool `json:"checksumMatch"`
}
func InitAdmissionController(conf *conf.AdmissionControllerConf, pcCache
*PriorityClassCache, nsCache *NamespaceCache) *AdmissionController {
@@ -594,7 +596,8 @@ func (c *AdmissionController) validateConfigMap(namespace
string, cm *v1.ConfigM
return err
}
- log.Log(log.Admission).Info("Successfully validated YuniKorn
configuration")
+ log.Log(log.Admission).Info("Successfully validated YuniKorn
configuration",
+ zap.String("checksum", responseData.Checksum),
zap.Bool("checksumMatch", responseData.ChecksumMatch))
return nil
}
diff --git a/pkg/admission/admission_controller_test.go
b/pkg/admission/admission_controller_test.go
index 3eee9c69..99d97858 100644
--- a/pkg/admission/admission_controller_test.go
+++ b/pkg/admission/admission_controller_test.go
@@ -335,6 +335,46 @@ func TestValidateConfigMapServerError(t *testing.T) {
assert.NilError(t, err, "No error expected")
}
+// Test for the case to check if validateConfigMap accepts a valid config
response with checksum
+func TestValidateConfigMapValidConfigWithChecksum(t *testing.T) {
+ configmap := prepareConfigMap(ConfigData)
+ srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter,
r *http.Request) {
+ w.WriteHeader(200)
+ resp := `{"allowed": true, "reason": "", "checksum": "ABC123",
"checksumMatch": false}`
+ w.Write([]byte(resp)) //nolint:errcheck
+ }))
+ defer srv.Close()
+ // both server and url pattern contains http://, so we need to delete
one
+ controller := prepareController(t, strings.Replace(srv.URL, "http://",
"", 1), "", "", "", "", false, true)
+ err := controller.validateConfigMap("yunikorn", configmap)
+ assert.NilError(t, err, "No error expected with checksum fields in
response")
+}
+
+// Test for the checksum fields returned by the scheduler validate-conf
response
+func TestValidateConfResponseChecksum(t *testing.T) {
+ tests := []struct {
+ name string
+ response string
+ wantAllowed bool
+ wantChecksum string
+ wantChkMatch bool
+ }{
+ {"checksum present and matching", `{"allowed": true, "reason":
"", "checksum": "ABC123", "checksumMatch": true}`, true, "ABC123", true},
+ {"checksum present not matching", `{"allowed": true, "reason":
"", "checksum": "ABC123", "checksumMatch": false}`, true, "ABC123", false},
+ {"checksum fields omitted", `{"allowed": true, "reason": ""}`,
true, "", false},
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ var data ValidateConfResponse
+ err := json.Unmarshal([]byte(tt.response), &data)
+ assert.NilError(t, err, "unexpected error unmarshalling
validate-conf response")
+ assert.Equal(t, data.Allowed, tt.wantAllowed, "allowed
flag not parsed as expected")
+ assert.Equal(t, data.Checksum, tt.wantChecksum,
"checksum not parsed as expected")
+ assert.Equal(t, data.ChecksumMatch, tt.wantChkMatch,
"checksumMatch flag not parsed as expected")
+ })
+ }
+}
+
func prepareConfigMap(data string) *v1.ConfigMap {
configmap := &v1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]