Skip to content

Commit 8c57953

Browse files
Damans227Daman Arora
andauthored
CKS: Allow affinity group selection during cluster creation (#12386)
Co-authored-by: Daman Arora <daman.arora@shapeblue.com>
1 parent faaf766 commit 8c57953

File tree

36 files changed

+3426
-222
lines changed

36 files changed

+3426
-222
lines changed

api/src/main/java/com/cloud/kubernetes/cluster/KubernetesCluster.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ enum State {
9898
s_fsm.addTransition(State.Running, Event.ScaleDownRequested, State.Scaling);
9999
s_fsm.addTransition(State.Stopped, Event.ScaleUpRequested, State.ScalingStoppedCluster);
100100
s_fsm.addTransition(State.Scaling, Event.OperationSucceeded, State.Running);
101-
s_fsm.addTransition(State.Scaling, Event.OperationFailed, State.Alert);
101+
s_fsm.addTransition(State.Scaling, Event.OperationFailed, State.Running);
102102
s_fsm.addTransition(State.ScalingStoppedCluster, Event.OperationSucceeded, State.Stopped);
103103
s_fsm.addTransition(State.ScalingStoppedCluster, Event.OperationFailed, State.Alert);
104104

api/src/main/java/com/cloud/kubernetes/cluster/KubernetesServiceHelper.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import org.apache.cloudstack.acl.ControlledEntity;
2020

21+
import java.util.List;
2122
import java.util.Map;
2223

2324
import com.cloud.user.Account;
@@ -33,8 +34,10 @@ enum KubernetesClusterNodeType {
3334
ControlledEntity findByUuid(String uuid);
3435
ControlledEntity findByVmId(long vmId);
3536
void checkVmCanBeDestroyed(UserVm userVm);
37+
void checkVmAffinityGroupsCanBeUpdated(UserVm userVm);
3638
boolean isValidNodeType(String nodeType);
3739
Map<String, Long> getServiceOfferingNodeTypeMap(Map<String, Map<String, String>> serviceOfferingNodeTypeMap);
3840
Map<String, Long> getTemplateNodeTypeMap(Map<String, Map<String, String>> templateNodeTypeMap);
41+
Map<String, List<Long>> getAffinityGroupNodeTypeMap(Map<String, Map<String, String>> affinityGroupNodeTypeMap);
3942
void cleanupForAccount(Account account);
4043
}

api/src/main/java/com/cloud/vm/VmDetailConstants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ public interface VmDetailConstants {
9696
String CKS_NODE_TYPE = "node";
9797
String OFFERING = "offering";
9898
String TEMPLATE = "template";
99+
String AFFINITY_GROUP = "affinitygroup";
99100

100101
// VMware to KVM VM migrations specific
101102
String VMWARE_TO_KVM_PREFIX = "vmware-to-kvm";

api/src/main/java/org/apache/cloudstack/affinity/AffinityGroupService.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,4 @@ public interface AffinityGroupService {
6666

6767
boolean isAffinityGroupAvailableInDomain(long affinityGroupId, long domainId);
6868

69-
7069
}

api/src/main/java/org/apache/cloudstack/affinity/AffinityProcessorBase.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929

3030
public class AffinityProcessorBase extends AdapterBase implements AffinityGroupProcessor {
3131

32+
public static final String AFFINITY_TYPE_HOST = "host affinity";
33+
public static final String AFFINITY_TYPE_HOST_ANTI = "host anti-affinity";
34+
3235
protected String _type;
3336

3437
@Override

api/src/main/java/org/apache/cloudstack/api/ApiConstants.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1244,6 +1244,13 @@ public class ApiConstants {
12441244
public static final String MAX_SIZE = "maxsize";
12451245
public static final String NODE_TYPE_OFFERING_MAP = "nodeofferings";
12461246
public static final String NODE_TYPE_TEMPLATE_MAP = "nodetemplates";
1247+
public static final String NODE_TYPE_AFFINITY_GROUP_MAP = "nodeaffinitygroups";
1248+
public static final String CONTROL_AFFINITY_GROUP_IDS = "controlaffinitygroupids";
1249+
public static final String CONTROL_AFFINITY_GROUP_NAMES = "controlaffinitygroupnames";
1250+
public static final String WORKER_AFFINITY_GROUP_IDS = "workeraffinitygroupids";
1251+
public static final String WORKER_AFFINITY_GROUP_NAMES = "workeraffinitygroupnames";
1252+
public static final String ETCD_AFFINITY_GROUP_IDS = "etcdaffinitygroupids";
1253+
public static final String ETCD_AFFINITY_GROUP_NAMES = "etcdaffinitygroupnames";
12471254

12481255
public static final String BOOT_TYPE = "boottype";
12491256
public static final String BOOT_MODE = "bootmode";

engine/schema/src/main/resources/META-INF/db/schema-42210to42300.sql

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,19 @@ CREATE TABLE `cloud`.`backup_offering_details` (
3434
UPDATE `cloud`.`configuration` SET value='random' WHERE name IN ('vm.allocation.algorithm', 'volume.allocation.algorithm') AND value='userconcentratedpod_random';
3535
UPDATE `cloud`.`configuration` SET value='firstfit' WHERE name IN ('vm.allocation.algorithm', 'volume.allocation.algorithm') AND value='userconcentratedpod_firstfit';
3636

37+
-- Create kubernetes_cluster_affinity_group_map table for CKS per-node-type affinity groups
38+
CREATE TABLE IF NOT EXISTS `cloud`.`kubernetes_cluster_affinity_group_map` (
39+
`id` bigint unsigned NOT NULL AUTO_INCREMENT,
40+
`cluster_id` bigint unsigned NOT NULL COMMENT 'kubernetes cluster id',
41+
`node_type` varchar(32) NOT NULL COMMENT 'CONTROL, WORKER, or ETCD',
42+
`affinity_group_id` bigint unsigned NOT NULL COMMENT 'affinity group id',
43+
PRIMARY KEY (`id`),
44+
CONSTRAINT `fk_kubernetes_cluster_ag_map__cluster_id` FOREIGN KEY (`cluster_id`) REFERENCES `kubernetes_cluster`(`id`) ON DELETE CASCADE,
45+
CONSTRAINT `fk_kubernetes_cluster_ag_map__ag_id` FOREIGN KEY (`affinity_group_id`) REFERENCES `affinity_group`(`id`) ON DELETE CASCADE,
46+
INDEX `i_kubernetes_cluster_ag_map__cluster_id`(`cluster_id`),
47+
INDEX `i_kubernetes_cluster_ag_map__ag_id`(`affinity_group_id`)
48+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
49+
3750
-- Create webhook_filter table
3851
DROP TABLE IF EXISTS `cloud`.`webhook_filter`;
3952
CREATE TABLE IF NOT EXISTS `cloud`.`webhook_filter` (
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
package com.cloud.kubernetes.cluster;
18+
19+
import javax.persistence.Column;
20+
import javax.persistence.Entity;
21+
import javax.persistence.GeneratedValue;
22+
import javax.persistence.GenerationType;
23+
import javax.persistence.Id;
24+
import javax.persistence.Table;
25+
26+
import org.apache.cloudstack.api.InternalIdentity;
27+
28+
@Entity
29+
@Table(name = "kubernetes_cluster_affinity_group_map")
30+
public class KubernetesClusterAffinityGroupMapVO implements InternalIdentity {
31+
32+
@Id
33+
@GeneratedValue(strategy = GenerationType.IDENTITY)
34+
@Column(name = "id")
35+
private Long id;
36+
37+
@Column(name = "cluster_id")
38+
private long clusterId;
39+
40+
@Column(name = "node_type")
41+
private String nodeType;
42+
43+
@Column(name = "affinity_group_id")
44+
private long affinityGroupId;
45+
46+
public KubernetesClusterAffinityGroupMapVO() {
47+
}
48+
49+
public KubernetesClusterAffinityGroupMapVO(long clusterId, String nodeType, long affinityGroupId) {
50+
this.clusterId = clusterId;
51+
this.nodeType = nodeType;
52+
this.affinityGroupId = affinityGroupId;
53+
}
54+
55+
@Override
56+
public long getId() {
57+
return id;
58+
}
59+
60+
public long getClusterId() {
61+
return clusterId;
62+
}
63+
64+
public void setClusterId(long clusterId) {
65+
this.clusterId = clusterId;
66+
}
67+
68+
public String getNodeType() {
69+
return nodeType;
70+
}
71+
72+
public void setNodeType(String nodeType) {
73+
this.nodeType = nodeType;
74+
}
75+
76+
public long getAffinityGroupId() {
77+
return affinityGroupId;
78+
}
79+
80+
public void setAffinityGroupId(long affinityGroupId) {
81+
this.affinityGroupId = affinityGroupId;
82+
}
83+
}

plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/KubernetesClusterEventTypes.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,5 @@ public class KubernetesClusterEventTypes {
2525
public static final String EVENT_KUBERNETES_CLUSTER_UPGRADE = "KUBERNETES.CLUSTER.UPGRADE";
2626
public static final String EVENT_KUBERNETES_CLUSTER_NODES_ADD = "KUBERNETES.CLUSTER.NODES.ADD";
2727
public static final String EVENT_KUBERNETES_CLUSTER_NODES_REMOVE = "KUBERNETES.CLUSTER.NODES.REMOVE";
28+
public static final String EVENT_KUBERNETES_CLUSTER_AFFINITY_UPDATE = "KUBERNETES.CLUSTER.AFFINITY.UPDATE";
2829
}

0 commit comments

Comments
 (0)