zncdatadev / hive-operator

Operator for Apache Hive
Apache License 2.0
5 stars 5 forks source link

[Feature]: Use default affinity Rules if none specified #81

Closed lwpk110 closed 1 month ago

lwpk110 commented 1 month ago

Duplicates

Summary 💡

  1. When creating workload resources (e.g. Deployment, StatefulSet etc.), default affinity rules will be used for scheduling if no affinity or anti-affinity rules are specified.
  2. The default affinity rules will group nodes and schedule pods to different nodes within the same group, avoiding putting everything on one machine. The default number of groups can be configured but no more than half the total number of machines.
  3. Users can still specify their own detailed affinity rules if needed. The system will ignore the default affinity rules if any rules are specified.

Examples 🌈

        assert_eq!(
            merged_config.affinity,
            StackableAffinity {
                pod_affinity: None,
                pod_anti_affinity: Some(PodAntiAffinity {
                    preferred_during_scheduling_ignored_during_execution: Some(vec![
                        WeightedPodAffinityTerm {
                            pod_affinity_term: PodAffinityTerm {
                                label_selector: Some(LabelSelector {
                                    match_labels: Some(BTreeMap::from([
                                        ("app.kubernetes.io/name".to_string(), "hive".to_string(),),
                                        (
                                            "app.kubernetes.io/instance".to_string(),
                                            "simple-hive".to_string(),
                                        ),
                                        (
                                            "app.kubernetes.io/component".to_string(),
                                            "metastore".to_string(),
                                        )
                                    ])),
                                    ..LabelSelector::default()
                                }),
                                topology_key: "kubernetes.io/hostname".to_string(),
                                ..PodAffinityTerm::default()
                            },
                            weight: 70
                        }
                    ]),
                    required_during_scheduling_ignored_during_execution: None,
                }),
                node_affinity: None,
                node_selector: None,
            }
        );

Motivation 🔦

Currently when creating workload resources like Deployments without specifying any affinity rules, it may lead to unbalanced resource distribution or difficulty in tracking resources. Adding default affinity rules can reduce user errors and better manage resource allocation.