-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
<!-- Thanks for sending a pull request! Here are some tips for you: 1. Run unit tests and ensure that they are passing 2. If your change introduces any API changes, make sure to update the e2e tests 3. Make sure documentation is updated for your PR! --> **What this PR does / why we need it**: <!-- Explain here the context and why you're making the change. What is the problem you're trying to solve. ---> 1. Fix PDB apply by supplying `FieldManager: "application/apply-patch"` kubernetes/client-go#1036 (comment) 2. Fix PDB config to always have % as suffix **Which issue(s) this PR fixes**: <!-- *Automatically closes linked issue when PR is merged. Usage: `Fixes #<issue number>`, or `Fixes (paste link of issue)`. --> Fixes PDB implementation **Does this PR introduce a user-facing change?**: <!-- If no, just write "NONE" in the release-note block below. If yes, a release note is required. Enter your extended release note in the block below. If the PR requires additional action from users switching to the new release, include the string "action required". For more information about release notes, see kubernetes' guide here: http://git.k8s.io/community/contributors/guide/release-notes.md --> ```release-note NONE ``` **Checklist** - [x] Added unit test, integration, and/or e2e tests - [x] Tested locally - [ ] Updated documentation - [ ] Update Swagger spec if the PR introduce API changes - [ ] Regenerated Golang and Python client if the PR introduce API changes
- Loading branch information
1 parent
48d8ca1
commit b2ed508
Showing
4 changed files
with
107 additions
and
8 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,100 @@ | ||
package cluster | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
|
||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/util/intstr" | ||
metav1cfg "k8s.io/client-go/applyconfigurations/meta/v1" | ||
policyv1cfg "k8s.io/client-go/applyconfigurations/policy/v1" | ||
) | ||
|
||
func TestPodDisruptionBudget_BuildPDBSpec(t *testing.T) { | ||
defaultInt := 20 | ||
defaultIntOrString := intstr.FromString("20%") | ||
defaultLabels := map[string]string{ | ||
"gojek.com/app": "sklearn-sample-s", | ||
} | ||
|
||
type fields struct { | ||
Name string | ||
Namespace string | ||
Labels map[string]string | ||
MaxUnavailablePercentage *int | ||
MinAvailablePercentage *int | ||
Selector *metav1.LabelSelector | ||
} | ||
tests := []struct { | ||
name string | ||
fields fields | ||
want *policyv1cfg.PodDisruptionBudgetSpecApplyConfiguration | ||
wantErr bool | ||
}{ | ||
{ | ||
name: "valid: enabled with min_available", | ||
fields: fields{ | ||
Name: "sklearn-sample-s-1-model-pdb", | ||
Namespace: "pdb-test", | ||
Labels: defaultLabels, | ||
MaxUnavailablePercentage: nil, | ||
MinAvailablePercentage: &defaultInt, | ||
}, | ||
want: &policyv1cfg.PodDisruptionBudgetSpecApplyConfiguration{ | ||
MinAvailable: &defaultIntOrString, | ||
Selector: &metav1cfg.LabelSelectorApplyConfiguration{ | ||
MatchLabels: defaultLabels, | ||
}, | ||
}, | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "valid: enabled but both max_unavailable and min_available specified. will use min available", | ||
fields: fields{ | ||
Name: "sklearn-sample-s-1-model-pdb", | ||
Namespace: "pdb-test", | ||
Labels: defaultLabels, | ||
MaxUnavailablePercentage: &defaultInt, | ||
MinAvailablePercentage: &defaultInt, | ||
}, | ||
want: &policyv1cfg.PodDisruptionBudgetSpecApplyConfiguration{ | ||
MinAvailable: &defaultIntOrString, | ||
Selector: &metav1cfg.LabelSelectorApplyConfiguration{ | ||
MatchLabels: defaultLabels, | ||
}, | ||
}, | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "invalid: enabled but no max_unavailable and min_available", | ||
fields: fields{ | ||
Name: "sklearn-sample-s-1-model-pdb", | ||
Namespace: "pdb-test", | ||
Labels: map[string]string{}, | ||
MaxUnavailablePercentage: nil, | ||
MinAvailablePercentage: nil, | ||
}, | ||
want: nil, | ||
wantErr: true, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
cfg := PodDisruptionBudget{ | ||
Name: tt.fields.Name, | ||
Namespace: tt.fields.Namespace, | ||
Labels: tt.fields.Labels, | ||
MaxUnavailablePercentage: tt.fields.MaxUnavailablePercentage, | ||
MinAvailablePercentage: tt.fields.MinAvailablePercentage, | ||
} | ||
got, err := cfg.BuildPDBSpec() | ||
if (err != nil) != tt.wantErr { | ||
t.Errorf("PodDisruptionBudget.BuildPDBSpec() error = %v, wantErr %v", err, tt.wantErr) | ||
return | ||
} | ||
if !reflect.DeepEqual(got, tt.want) { | ||
t.Errorf("PodDisruptionBudget.BuildPDBSpec() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |
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