-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[v0.4] Prevent dropping unknown cluster fields (#517)
* Prevents dropping unknown cluster fields Signed-off-by: Dharmit Shah <[email protected]> * add test for v3 cluster mutator & add rke to replace in go.mod adding rke to replace section will avoid pulling in rc versions when updating pkg/apis in webhook
- Loading branch information
1 parent
f851349
commit d75633a
Showing
3 changed files
with
55 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
pkg/resources/management.cattle.io/v3/cluster/mutator_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package cluster | ||
|
||
import ( | ||
"encoding/json" | ||
"testing" | ||
|
||
v3 "github.com/rancher/rancher/pkg/apis/management.cattle.io/v3" | ||
"github.com/rancher/webhook/pkg/admission" | ||
data2 "github.com/rancher/wrangler/v2/pkg/data" | ||
"github.com/stretchr/testify/assert" | ||
admissionv1 "k8s.io/api/admission/v1" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
) | ||
|
||
func TestAdmitPreserveUnknownFields(t *testing.T) { | ||
cluster := &v3.Cluster{} | ||
data, err := data2.Convert(cluster) | ||
assert.Nil(t, err) | ||
|
||
data.SetNested("test", "spec", "rancherKubernetesEngineConfig", "network", "aciNetworkProvider", "apicUserKeyTest") | ||
raw, err := json.Marshal(data) | ||
assert.Nil(t, err) | ||
|
||
request := &admission.Request{ | ||
AdmissionRequest: admissionv1.AdmissionRequest{ | ||
Object: runtime.RawExtension{ | ||
Raw: raw, | ||
}, | ||
OldObject: runtime.RawExtension{ | ||
Raw: raw, | ||
}, | ||
}, | ||
} | ||
|
||
m := ManagementClusterMutator{} | ||
|
||
request.Operation = admissionv1.Create | ||
response, err := m.Admit(request) | ||
assert.Nil(t, err) | ||
assert.Nil(t, response.Patch) | ||
|
||
request.Operation = admissionv1.Update | ||
response, err = m.Admit(request) | ||
assert.Nil(t, err) | ||
assert.Nil(t, response.Patch) | ||
} |