Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add APIVersion and Kind checks for helper.ToUnstructured() #6028

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions pkg/controllers/multiclusterservice/mcs_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,10 @@ func TestPropagateMultiClusterService(t *testing.T) {
{
name: "Propagate to one ready cluster",
mcs: &networkingv1alpha1.MultiClusterService{
TypeMeta: metav1.TypeMeta{
Kind: "MultiClusterService",
APIVersion: networkingv1alpha1.GroupVersion.String(),
},
ObjectMeta: metav1.ObjectMeta{
Name: "test-mcs",
Namespace: "default",
Expand Down Expand Up @@ -353,6 +357,10 @@ func TestPropagateMultiClusterService(t *testing.T) {
{
name: "Propagate to multiple ready clusters",
mcs: &networkingv1alpha1.MultiClusterService{
TypeMeta: metav1.TypeMeta{
Kind: "MultiClusterService",
APIVersion: networkingv1alpha1.GroupVersion.String(),
},
ObjectMeta: metav1.ObjectMeta{
Name: "test-mcs",
Namespace: "default",
Expand Down Expand Up @@ -401,6 +409,10 @@ func TestPropagateMultiClusterService(t *testing.T) {
{
name: "Mixed cluster readiness and API support",
mcs: &networkingv1alpha1.MultiClusterService{
TypeMeta: metav1.TypeMeta{
Kind: "MultiClusterService",
APIVersion: networkingv1alpha1.GroupVersion.String(),
},
ObjectMeta: metav1.ObjectMeta{
Name: "test-mcs",
Namespace: "default",
Expand Down
21 changes: 20 additions & 1 deletion pkg/controllers/namespace/namespace_sync_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ func TestController_Reconcile(t *testing.T) {
{
name: "Namespace should be synced",
namespace: &corev1.Namespace{
TypeMeta: metav1.TypeMeta{
Kind: "Namespace",
APIVersion: corev1.SchemeGroupVersion.String(),
},
ObjectMeta: metav1.ObjectMeta{
Name: "test-namespace",
},
Expand All @@ -120,6 +124,10 @@ func TestController_Reconcile(t *testing.T) {
{
name: "Namespace should not be synced",
namespace: &corev1.Namespace{
TypeMeta: metav1.TypeMeta{
Kind: "Namespace",
APIVersion: corev1.SchemeGroupVersion.String(),
},
ObjectMeta: metav1.ObjectMeta{
Name: "kube-system",
},
Expand All @@ -144,6 +152,10 @@ func TestController_Reconcile(t *testing.T) {
{
name: "Namespace should not be synced - kube-public",
namespace: &corev1.Namespace{
TypeMeta: metav1.TypeMeta{
Kind: "Namespace",
APIVersion: corev1.SchemeGroupVersion.String(),
},
ObjectMeta: metav1.ObjectMeta{
Name: "kube-public",
},
Expand Down Expand Up @@ -247,8 +259,15 @@ func TestController_buildWorks(t *testing.T) {
_ = policyv1alpha1.Install(scheme)

namespace := &corev1.Namespace{
TypeMeta: metav1.TypeMeta{
Kind: "Namespace",
APIVersion: corev1.SchemeGroupVersion.String(),
},
ObjectMeta: metav1.ObjectMeta{
Name: "test-namespace",
Labels: map[string]string{
"overridden": "false",
},
},
}

Expand All @@ -272,7 +291,7 @@ func TestController_buildWorks(t *testing.T) {
Spec: policyv1alpha1.OverrideSpec{
ResourceSelectors: []policyv1alpha1.ResourceSelector{
{
APIVersion: "v1",
APIVersion: corev1.SchemeGroupVersion.String(),
Kind: "Namespace",
Name: "test-namespace",
},
Expand Down
10 changes: 9 additions & 1 deletion pkg/detector/detector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,10 @@ func TestOnUpdate(t *testing.T) {
{
name: "core v1 object",
oldObj: &corev1.Pod{
TypeMeta: metav1.TypeMeta{
Kind: "Pod",
APIVersion: corev1.SchemeGroupVersion.String(),
},
ObjectMeta: metav1.ObjectMeta{
Name: "test-pod",
Namespace: "default",
Expand All @@ -541,6 +545,10 @@ func TestOnUpdate(t *testing.T) {
},
},
newObj: &corev1.Pod{
TypeMeta: metav1.TypeMeta{
Kind: "Pod",
APIVersion: corev1.SchemeGroupVersion.String(),
},
ObjectMeta: metav1.ObjectMeta{
Name: "test-pod",
Namespace: "default",
Expand Down Expand Up @@ -1023,7 +1031,7 @@ func TestApplyClusterPolicy(t *testing.T) {
}
}

//Helper Functions
// Helper Functions

// setupTestScheme creates a runtime scheme with necessary types for testing
func setupTestScheme() *runtime.Scheme {
Expand Down
17 changes: 12 additions & 5 deletions pkg/resourceinterpreter/customized/declarative/luavm/lua_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,13 +286,17 @@ func TestAggregateDeploymentStatus(t *testing.T) {
oldDeploy := &appsv1.Deployment{
TypeMeta: metav1.TypeMeta{
Kind: "Deployment",
APIVersion: "apps/v1",
APIVersion: appsv1.SchemeGroupVersion.String(),
},
Status: appsv1.DeploymentStatus{Replicas: 0, ReadyReplicas: 1, UpdatedReplicas: 0, AvailableReplicas: 0, UnavailableReplicas: 0},
}
oldDeploy.Status = appsv1.DeploymentStatus{
Replicas: 0, ReadyReplicas: 1, UpdatedReplicas: 0, AvailableReplicas: 0, UnavailableReplicas: 0}

newDeploy := &appsv1.Deployment{Status: appsv1.DeploymentStatus{Replicas: 0, ReadyReplicas: 3, UpdatedReplicas: 0, AvailableReplicas: 0, UnavailableReplicas: 0}}
newDeploy := &appsv1.Deployment{
TypeMeta: metav1.TypeMeta{
Kind: "Deployment",
APIVersion: appsv1.SchemeGroupVersion.String(),
},
Status: appsv1.DeploymentStatus{Replicas: 0, ReadyReplicas: 3, UpdatedReplicas: 0, AvailableReplicas: 0, UnavailableReplicas: 0}}
oldObj, _ := helper.ToUnstructured(oldDeploy)
newObj, _ := helper.ToUnstructured(newDeploy)

Expand Down Expand Up @@ -339,10 +343,13 @@ func TestAggregateDeploymentStatus(t *testing.T) {
func TestHealthDeploymentStatus(t *testing.T) {
var cnt int32 = 2
newDeploy := &appsv1.Deployment{
TypeMeta: metav1.TypeMeta{
Kind: "Deployment",
APIVersion: appsv1.SchemeGroupVersion.String(),
},
Spec: appsv1.DeploymentSpec{
Replicas: &cnt,
},

ObjectMeta: metav1.ObjectMeta{
Generation: 1,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,10 @@ func TestUpdateConfiguration(t *testing.T) {
name: "valid configurations",
configs: []runtime.Object{
&configv1alpha1.ResourceInterpreterWebhookConfiguration{
TypeMeta: metav1.TypeMeta{
Kind: "ResourceInterpreterWebhookConfiguration",
APIVersion: configv1alpha1.GroupVersion.String(),
},
ObjectMeta: metav1.ObjectMeta{Name: "config1"},
Webhooks: []configv1alpha1.ResourceInterpreterWebhook{
{Name: "webhook1"},
Expand Down
Loading