-
Notifications
You must be signed in to change notification settings - Fork 226
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1482 from raulcabello/bundle-error-state
Add ignore conditions
- Loading branch information
Showing
5 changed files
with
223 additions
and
3 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
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,78 @@ | ||
package deployer | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
fleet "github.com/rancher/fleet/pkg/apis/fleet.cattle.io/v1alpha1" | ||
v1 "k8s.io/api/core/v1" | ||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
) | ||
|
||
func TestExcludeIgnoredConditions(t *testing.T) { | ||
podInitializedAndNotReady := v1.Pod{Status: v1.PodStatus{ | ||
Conditions: []v1.PodCondition{{Type: v1.PodReady, Status: v1.ConditionFalse}, {Type: v1.PodInitialized, Status: v1.ConditionTrue}}, | ||
}} | ||
uPodInitializedAndNotReady, err := runtime.DefaultUnstructuredConverter.ToUnstructured(&podInitializedAndNotReady) | ||
if err != nil { | ||
t.Errorf("can't convert podInitializedAndNotReady to unstructured: %v", err) | ||
} | ||
podInitialized := v1.Pod{Status: v1.PodStatus{ | ||
Conditions: []v1.PodCondition{{Type: v1.PodInitialized, Status: v1.ConditionTrue}}, | ||
}} | ||
uPodInitialized, err := runtime.DefaultUnstructuredConverter.ToUnstructured(&podInitialized) | ||
if err != nil { | ||
t.Errorf("can't convert podInitialized to unstructured: %v", err) | ||
} | ||
tests := map[string]struct { | ||
obj *unstructured.Unstructured | ||
ignoreOptions fleet.IgnoreOptions | ||
expectedObj *unstructured.Unstructured | ||
expectedErr error | ||
}{ | ||
"nothing is changed without IgnoreOptions": { | ||
obj: &unstructured.Unstructured{Object: uPodInitializedAndNotReady}, | ||
ignoreOptions: fleet.IgnoreOptions{}, | ||
expectedObj: &unstructured.Unstructured{Object: uPodInitializedAndNotReady}, | ||
expectedErr: nil, | ||
}, | ||
"nothing is changed when IgnoreOptions don't match any condition": { | ||
obj: &unstructured.Unstructured{Object: uPodInitializedAndNotReady}, | ||
ignoreOptions: fleet.IgnoreOptions{Conditions: []map[string]string{{"Not": "Found"}}}, | ||
expectedObj: &unstructured.Unstructured{Object: uPodInitializedAndNotReady}, | ||
expectedErr: nil, | ||
}, | ||
"'Type: Ready' condition is excluded when IgnoreOptions contains 'Type: Ready' condition": { | ||
obj: &unstructured.Unstructured{Object: uPodInitializedAndNotReady}, | ||
ignoreOptions: fleet.IgnoreOptions{Conditions: []map[string]string{{"type": "Ready"}}}, | ||
expectedObj: &unstructured.Unstructured{Object: uPodInitialized}, | ||
expectedErr: nil, | ||
}, | ||
"'Type: Ready' condition is excluded when IgnoreOptions contains 'Type: Ready, status: False' condition": { | ||
obj: &unstructured.Unstructured{Object: uPodInitializedAndNotReady}, | ||
ignoreOptions: fleet.IgnoreOptions{Conditions: []map[string]string{{"type": "Ready", "status": "False"}}}, | ||
expectedObj: &unstructured.Unstructured{Object: uPodInitialized}, | ||
expectedErr: nil, | ||
}, | ||
"nothing is changed when IgnoreOptions contains 'type: Ready, status: True' condition": { | ||
obj: &unstructured.Unstructured{Object: uPodInitializedAndNotReady}, | ||
ignoreOptions: fleet.IgnoreOptions{Conditions: []map[string]string{{"type": "Ready", "status": "True"}}}, | ||
expectedObj: &unstructured.Unstructured{Object: uPodInitializedAndNotReady}, | ||
expectedErr: nil, | ||
}, | ||
} | ||
|
||
for name, test := range tests { | ||
t.Run(name, func(t *testing.T) { | ||
obj := test.obj | ||
err := excludeIgnoredConditions(obj, test.ignoreOptions) | ||
if err != test.expectedErr { | ||
t.Errorf("expected error doesn't match: expected %v, got %v", test.expectedErr, err) | ||
} | ||
if !cmp.Equal(obj, test.expectedObj) { | ||
t.Errorf("objects don't match: expected %v, got %v", test.expectedObj, obj) | ||
} | ||
}) | ||
} | ||
} |
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
30 changes: 30 additions & 0 deletions
30
pkg/apis/fleet.cattle.io/v1alpha1/zz_generated_deepcopy.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.