-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Disallow only spec updates for now (#1146)
What this PR does / why we need it: For now, we disallowed all updates except status updates. This narrows it down and just disallows updates to the spec that means: - no change in params - no change in OV This potentially narrows down issues with the webhook as controller etc. can update annotation or finalizers, which I think is fine even when plan is running. Addition to #883
- Loading branch information
Showing
2 changed files
with
72 additions
and
4 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package v1beta1 | ||
|
||
import ( | ||
"errors" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"sigs.k8s.io/controller-runtime/pkg/webhook/admission" | ||
|
||
v1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
func TestValidateUpdate(t *testing.T) { | ||
runningInstance := Instance{ | ||
TypeMeta: metav1.TypeMeta{ | ||
APIVersion: "kudo.dev/v1beta1", | ||
Kind: "Instance", | ||
}, | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "test", | ||
Namespace: "test", | ||
}, | ||
Spec: InstanceSpec{ | ||
OperatorVersion: v1.ObjectReference{ | ||
Name: "test-1.0", | ||
}, | ||
}, | ||
Status: InstanceStatus{ | ||
AggregatedStatus: AggregatedStatus{ | ||
Status: ExecutionInProgress, | ||
ActivePlanName: "deploy", | ||
}, | ||
}, | ||
} | ||
|
||
req := admission.Request{} | ||
|
||
tests := []struct { | ||
name string | ||
i Instance | ||
oldInstance Instance | ||
expectedError error | ||
}{ | ||
{"no change", runningInstance, runningInstance, nil}, | ||
{"change in labels is allowed on running instance", runningInstance, func() Instance { | ||
updatedInstance := runningInstance.DeepCopy() | ||
updatedInstance.ObjectMeta.Labels = map[string]string{"label": "label2"} | ||
return *updatedInstance | ||
}(), nil}, | ||
{"change in spec is not allowed on running instance", runningInstance, func() Instance { | ||
updatedInstance := runningInstance.DeepCopy() | ||
updatedInstance.Spec.Parameters = map[string]string{"newparam": "newvalue"} | ||
return *updatedInstance | ||
}(), errors.New("cannot update Instance test/test right now, there's plan deploy in progress")}, | ||
} | ||
|
||
for _, tt := range tests { | ||
err := tt.i.ValidateUpdate(&tt.oldInstance, req) | ||
assert.Equal(t, tt.expectedError, err) | ||
} | ||
} |