Skip to content

Commit

Permalink
Merge branch 'main' into fix/ergonomic-annotation-handling
Browse files Browse the repository at this point in the history
  • Loading branch information
gary-lgy authored Jul 13, 2023
2 parents eab1527 + 185b98e commit f973cbc
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 3 deletions.
3 changes: 2 additions & 1 deletion pkg/controllers/federatedcluster/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ func NewFederatedClusterController(
federatedClient: federatedClient,
fedSystemNamespace: fedsystemNamespace,
clusterHealthCheckConfig: &ClusterHealthCheckConfig{
Period: time.Minute,
// TODO: make health check period configurable
Period: time.Second * 30,
},
clusterJoinTimeout: clusterJoinTimeout,
metrics: metrics,
Expand Down
34 changes: 33 additions & 1 deletion pkg/controllers/scheduler/scheduler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -441,8 +441,37 @@ func TestGetSchedulingUnitWithAnnotationOverrides(t *testing.T) {
}

func TestSchedulingMode(t *testing.T) {
deploymentObj, err := runtime.DefaultUnstructuredConverter.ToUnstructured(&appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Name: "deployment",
Namespace: "default",
},
Spec: appsv1.DeploymentSpec{
Replicas: pointer.Int32(10),
},
})
if err != nil {
t.Fatal(err)
}
deploymentUns := &unstructured.Unstructured{Object: deploymentObj}

statefulSetObj, err := runtime.DefaultUnstructuredConverter.ToUnstructured(&appsv1.StatefulSet{
ObjectMeta: metav1.ObjectMeta{
Name: "statefulset",
Namespace: "default",
},
Spec: appsv1.StatefulSetSpec{
Replicas: pointer.Int32(10),
},
})
if err != nil {
t.Fatal(err)
}
statefulSetUns := &unstructured.Unstructured{Object: statefulSetObj}

tests := map[string]struct {
policy fedcorev1a1.GenericPropagationPolicy
obj *unstructured.Unstructured
gvk schema.GroupVersionKind
replicasSpecPath string
expectedResult fedcorev1a1.SchedulingMode
Expand All @@ -453,6 +482,7 @@ func TestSchedulingMode(t *testing.T) {
SchedulingMode: fedcorev1a1.SchedulingModeDivide,
},
},
obj: deploymentUns,
replicasSpecPath: "spec.replicas",
gvk: appsv1.SchemeGroupVersion.WithKind("Deployment"),
expectedResult: fedcorev1a1.SchedulingModeDivide,
Expand All @@ -463,6 +493,7 @@ func TestSchedulingMode(t *testing.T) {
SchedulingMode: fedcorev1a1.SchedulingModeDuplicate,
},
},
obj: deploymentUns,
replicasSpecPath: "spec.replicas",
gvk: appsv1.SchemeGroupVersion.WithKind("Deployment"),
expectedResult: fedcorev1a1.SchedulingModeDuplicate,
Expand All @@ -473,6 +504,7 @@ func TestSchedulingMode(t *testing.T) {
SchedulingMode: fedcorev1a1.SchedulingModeDivide,
},
},
obj: statefulSetUns,
replicasSpecPath: "",
gvk: appsv1.SchemeGroupVersion.WithKind("StatefulSet"),
expectedResult: fedcorev1a1.SchedulingModeDuplicate,
Expand All @@ -498,7 +530,7 @@ func TestSchedulingMode(t *testing.T) {
},
}
obj := &unstructured.Unstructured{Object: make(map[string]interface{})}
err := unstructured.SetNestedMap(obj.Object, make(map[string]interface{}), common.TemplatePath...)
err := unstructured.SetNestedMap(obj.Object, test.obj.Object, common.TemplatePath...)
g.Expect(err).NotTo(gomega.HaveOccurred())
su, err := schedulingUnitForFedObject(typeConfig, obj, test.policy)
g.Expect(err).NotTo(gomega.HaveOccurred())
Expand Down
3 changes: 3 additions & 0 deletions pkg/controllers/scheduler/schedulingunit.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ func schedulingUnitForFedObject(
if err != nil {
return nil, err
}
if value == nil {
return nil, fmt.Errorf("replicas path \"%s\" does not exist for FederatedObject", typeConfig.Spec.PathDefinition.ReplicasSpec)
}

desiredReplicasOption = value
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/controllers/sync/dispatch/checkunmanaged.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"fmt"

apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/klog/v2"
Expand Down Expand Up @@ -80,7 +81,7 @@ func (d *checkUnmanagedDispatcherImpl) CheckRemovedOrUnlabeled(ctx context.Conte
clusterObj := &unstructured.Unstructured{}
clusterObj.SetGroupVersionKind(d.targetGVK)
err := client.Get(context.Background(), clusterObj, targetName.Namespace, targetName.Name)
if apierrors.IsNotFound(err) {
if apierrors.IsNotFound(err) || meta.IsNoMatchError(err) {
return true
}
if err != nil {
Expand Down

0 comments on commit f973cbc

Please sign in to comment.