-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
cks: fix events #9070
cks: fix events #9070
Changes from 8 commits
4afcdaa
5402a3b
7e043b6
8ea29de
24550ef
8f85b26
6085e74
29c94e0
0705e45
3e5a37b
6fcc914
1ffae17
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,12 +40,11 @@ | |
import javax.inject.Inject; | ||
import javax.naming.ConfigurationException; | ||
|
||
import com.cloud.uservm.UserVm; | ||
import com.cloud.vm.UserVmService; | ||
import org.apache.cloudstack.acl.ControlledEntity; | ||
import org.apache.cloudstack.acl.SecurityChecker; | ||
import org.apache.cloudstack.annotation.AnnotationService; | ||
import org.apache.cloudstack.annotation.dao.AnnotationDao; | ||
import org.apache.cloudstack.api.ApiCommandResourceType; | ||
import org.apache.cloudstack.api.ApiConstants; | ||
import org.apache.cloudstack.api.ApiConstants.VMDetails; | ||
import org.apache.cloudstack.api.BaseCmd; | ||
|
@@ -92,6 +91,7 @@ | |
import com.cloud.dc.dao.DataCenterDao; | ||
import com.cloud.deploy.DeployDestination; | ||
import com.cloud.domain.Domain; | ||
import com.cloud.event.ActionEvent; | ||
import com.cloud.exception.ConcurrentOperationException; | ||
import com.cloud.exception.InsufficientCapacityException; | ||
import com.cloud.exception.InsufficientServerCapacityException; | ||
|
@@ -159,6 +159,7 @@ | |
import com.cloud.user.UserVO; | ||
import com.cloud.user.dao.SSHKeyPairDao; | ||
import com.cloud.user.dao.UserDao; | ||
import com.cloud.uservm.UserVm; | ||
import com.cloud.utils.Pair; | ||
import com.cloud.utils.Ternary; | ||
import com.cloud.utils.component.ComponentContext; | ||
|
@@ -176,6 +177,7 @@ | |
import com.cloud.utils.fsm.NoTransitionException; | ||
import com.cloud.utils.fsm.StateMachine2; | ||
import com.cloud.utils.net.NetUtils; | ||
import com.cloud.vm.UserVmService; | ||
import com.cloud.vm.VMInstanceVO; | ||
import com.cloud.vm.VirtualMachine; | ||
import com.cloud.vm.dao.VMInstanceDao; | ||
|
@@ -863,13 +865,15 @@ | |
LOGGER.info(String.format("Creating network for account ID: %s from the network offering ID: %s as part of Kubernetes cluster: %s deployment process", owner.getUuid(), networkOffering.getUuid(), clusterName)); | ||
} | ||
|
||
CallContext networkContext = CallContext.register(CallContext.current(), ApiCommandResourceType.Network); | ||
Check warning on line 868 in plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/KubernetesClusterManagerImpl.java Codecov / codecov/patchplugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/KubernetesClusterManagerImpl.java#L868
|
||
try { | ||
network = networkMgr.createGuestNetwork(networkOffering.getId(), clusterName + "-network", owner.getAccountName() + "-network", | ||
null, null, null, false, null, owner, null, physicalNetwork, zone.getId(), | ||
ControlledEntity.ACLType.Account, null, null, null, null, true, null, | ||
null, null, null, null, null, null, null, null, null); | ||
network = networkService.createGuestNetwork(networkOffering.getId(), clusterName + "-network", | ||
owner.getAccountName() + "-network", owner, physicalNetwork, zone.getId(), | ||
Check warning on line 871 in plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/KubernetesClusterManagerImpl.java Codecov / codecov/patchplugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/KubernetesClusterManagerImpl.java#L870-L871
|
||
ControlledEntity.ACLType.Account); | ||
} catch (ConcurrentOperationException | InsufficientCapacityException | ResourceAllocationException e) { | ||
logAndThrow(Level.ERROR, String.format("Unable to create network for the Kubernetes cluster: %s", clusterName)); | ||
} finally { | ||
CallContext.unregister(); | ||
Check warning on line 876 in plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/KubernetesClusterManagerImpl.java Codecov / codecov/patchplugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/KubernetesClusterManagerImpl.java#L876
|
||
} | ||
} | ||
return network; | ||
|
@@ -1138,6 +1142,8 @@ | |
} | ||
|
||
@Override | ||
@ActionEvent(eventType = KubernetesClusterEventTypes.EVENT_KUBERNETES_CLUSTER_CREATE, | ||
eventDescription = "creating Kubernetes cluster", create = true) | ||
public KubernetesCluster createUnmanagedKubernetesCluster(CreateKubernetesClusterCmd cmd) throws CloudRuntimeException { | ||
if (!KubernetesServiceEnabled.value()) { | ||
logAndThrow(Level.ERROR, "Kubernetes Service plugin is disabled"); | ||
|
@@ -1184,10 +1190,13 @@ | |
if (LOGGER.isInfoEnabled()) { | ||
LOGGER.info(String.format("Kubernetes cluster with name: %s and ID: %s has been created", cluster.getName(), cluster.getUuid())); | ||
} | ||
CallContext.current().putContextParameter(KubernetesCluster.class, cluster.getUuid()); | ||
Check warning on line 1193 in plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/KubernetesClusterManagerImpl.java Codecov / codecov/patchplugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/KubernetesClusterManagerImpl.java#L1193
|
||
return cluster; | ||
} | ||
|
||
@Override | ||
@ActionEvent(eventType = KubernetesClusterEventTypes.EVENT_KUBERNETES_CLUSTER_CREATE, | ||
eventDescription = "creating Kubernetes cluster", create = true) | ||
public KubernetesCluster createManagedKubernetesCluster(CreateKubernetesClusterCmd cmd) throws CloudRuntimeException { | ||
if (!KubernetesServiceEnabled.value()) { | ||
logAndThrow(Level.ERROR, "Kubernetes Service plugin is disabled"); | ||
|
@@ -1244,6 +1253,7 @@ | |
if (LOGGER.isInfoEnabled()) { | ||
LOGGER.info(String.format("Kubernetes cluster name: %s and ID: %s has been created", cluster.getName(), cluster.getUuid())); | ||
} | ||
CallContext.current().putContextParameter(KubernetesCluster.class, cluster.getUuid()); | ||
Check warning on line 1256 in plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/KubernetesClusterManagerImpl.java Codecov / codecov/patchplugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/KubernetesClusterManagerImpl.java#L1256
|
||
return cluster; | ||
} | ||
|
||
|
@@ -1270,29 +1280,64 @@ | |
return securityGroup; | ||
} | ||
|
||
@Override | ||
@ActionEvent(eventType = KubernetesClusterEventTypes.EVENT_KUBERNETES_CLUSTER_CREATE, | ||
eventDescription = "creating Kubernetes cluster", async = true) | ||
public void startKubernetesCluster(CreateKubernetesClusterCmd cmd) throws CloudRuntimeException { | ||
final Long id = cmd.getEntityId(); | ||
Check warning on line 1287 in plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/KubernetesClusterManagerImpl.java Codecov / codecov/patchplugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/KubernetesClusterManagerImpl.java#L1286-L1287
|
||
if (KubernetesCluster.ClusterType.valueOf(cmd.getClusterType()) != KubernetesCluster.ClusterType.CloudManaged) { | ||
return; | ||
Check warning on line 1289 in plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/KubernetesClusterManagerImpl.java Codecov / codecov/patchplugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/KubernetesClusterManagerImpl.java#L1289
|
||
} | ||
final KubernetesClusterVO kubernetesCluster = kubernetesClusterDao.findById(id); | ||
Check warning on line 1291 in plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/KubernetesClusterManagerImpl.java Codecov / codecov/patchplugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/KubernetesClusterManagerImpl.java#L1291
|
||
if (kubernetesCluster == null) { | ||
throw new InvalidParameterValueException("Failed to find Kubernetes cluster with given ID"); | ||
Check warning on line 1293 in plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/KubernetesClusterManagerImpl.java Codecov / codecov/patchplugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/KubernetesClusterManagerImpl.java#L1293
|
||
} | ||
if (!startKubernetesCluster(kubernetesCluster, true)) { | ||
throw new CloudRuntimeException(String.format("Failed to start created Kubernetes cluster: %s", | ||
kubernetesCluster.getName())); | ||
Check warning on line 1297 in plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/KubernetesClusterManagerImpl.java Codecov / codecov/patchplugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/KubernetesClusterManagerImpl.java#L1296-L1297
|
||
} | ||
} | ||
Check warning on line 1299 in plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/KubernetesClusterManagerImpl.java Codecov / codecov/patchplugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/KubernetesClusterManagerImpl.java#L1299
|
||
|
||
@Override | ||
@ActionEvent(eventType = KubernetesClusterEventTypes.EVENT_KUBERNETES_CLUSTER_START, | ||
eventDescription = "starting Kubernetes cluster", async = true) | ||
public void startKubernetesCluster(StartKubernetesClusterCmd cmd) throws CloudRuntimeException { | ||
final Long id = cmd.getId(); | ||
Check warning on line 1305 in plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/KubernetesClusterManagerImpl.java Codecov / codecov/patchplugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/KubernetesClusterManagerImpl.java#L1304-L1305
|
||
if (id == null || id < 1L) { | ||
throw new InvalidParameterValueException("Invalid Kubernetes cluster ID provided"); | ||
Check warning on line 1307 in plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/KubernetesClusterManagerImpl.java Codecov / codecov/patchplugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/KubernetesClusterManagerImpl.java#L1307
|
||
} | ||
final KubernetesClusterVO kubernetesCluster = kubernetesClusterDao.findById(id); | ||
Check warning on line 1309 in plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/KubernetesClusterManagerImpl.java Codecov / codecov/patchplugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/KubernetesClusterManagerImpl.java#L1309
|
||
if (kubernetesCluster == null) { | ||
throw new InvalidParameterValueException("Given Kubernetes cluster was not found"); | ||
Check warning on line 1311 in plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/KubernetesClusterManagerImpl.java Codecov / codecov/patchplugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/KubernetesClusterManagerImpl.java#L1311
|
||
} | ||
if (!isCommandSupported(kubernetesCluster, cmd.getActualCommandName())) { | ||
throw new InvalidParameterValueException(String.format("Start kubernetes cluster is not supported for " + | ||
"an externally managed cluster (%s)", kubernetesCluster.getName())); | ||
Check warning on line 1315 in plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/KubernetesClusterManagerImpl.java Codecov / codecov/patchplugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/KubernetesClusterManagerImpl.java#L1314-L1315
|
||
} | ||
if (!startKubernetesCluster(kubernetesCluster, false)) { | ||
throw new CloudRuntimeException(String.format("Failed to start Kubernetes cluster: %s", | ||
kubernetesCluster.getName())); | ||
Check warning on line 1319 in plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/KubernetesClusterManagerImpl.java Codecov / codecov/patchplugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/KubernetesClusterManagerImpl.java#L1318-L1319
|
||
} | ||
} | ||
Check warning on line 1321 in plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/KubernetesClusterManagerImpl.java Codecov / codecov/patchplugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/KubernetesClusterManagerImpl.java#L1321
|
||
|
||
/** | ||
* Start operation can be performed at two different life stages of Kubernetes cluster. First when a freshly created cluster | ||
* in which case there are no resources provisioned for the Kubernetes cluster. So during start all the resources | ||
* are provisioned from scratch. Second kind of start, happens on Stopped Kubernetes cluster, in which all resources | ||
* are provisioned (like volumes, nics, networks etc). It just that VM's are not in running state. So just | ||
* start the VM's (which can possibly implicitly start the network also). | ||
* @param kubernetesClusterId | ||
* @param kubernetesCluster | ||
* @param onCreate | ||
* @return | ||
* @throws CloudRuntimeException | ||
*/ | ||
|
||
@Override | ||
public boolean startKubernetesCluster(long kubernetesClusterId, boolean onCreate) throws CloudRuntimeException { | ||
public boolean startKubernetesCluster(KubernetesClusterVO kubernetesCluster, boolean onCreate) throws CloudRuntimeException { | ||
Check warning on line 1334 in plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/KubernetesClusterManagerImpl.java Codecov / codecov/patchplugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/KubernetesClusterManagerImpl.java#L1334
|
||
if (!KubernetesServiceEnabled.value()) { | ||
logAndThrow(Level.ERROR, "Kubernetes Service plugin is disabled"); | ||
} | ||
final KubernetesClusterVO kubernetesCluster = kubernetesClusterDao.findById(kubernetesClusterId); | ||
if (kubernetesCluster == null) { | ||
throw new InvalidParameterValueException("Failed to find Kubernetes cluster with given ID"); | ||
} | ||
if (kubernetesCluster.getRemoved() != null) { | ||
throw new InvalidParameterValueException(String.format("Kubernetes cluster : %s is already deleted", kubernetesCluster.getName())); | ||
throw new InvalidParameterValueException(String.format("Kubernetes cluster : %s is already deleted", | ||
kubernetesCluster.getName())); | ||
Check warning on line 1340 in plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/KubernetesClusterManagerImpl.java Codecov / codecov/patchplugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/KubernetesClusterManagerImpl.java#L1339-L1340
|
||
} | ||
accountManager.checkAccess(CallContext.current().getCallingAccount(), SecurityChecker.AccessType.OperateEntry, false, kubernetesCluster); | ||
if (kubernetesCluster.getState().equals(KubernetesCluster.State.Running)) { | ||
|
@@ -1350,6 +1395,8 @@ | |
} | ||
|
||
@Override | ||
@ActionEvent(eventType = KubernetesClusterEventTypes.EVENT_KUBERNETES_CLUSTER_STOP, | ||
eventDescription = "stopping Kubernetes cluster", async = true) | ||
public boolean stopKubernetesCluster(StopKubernetesClusterCmd cmd) throws CloudRuntimeException { | ||
long kubernetesClusterId = cmd.getId(); | ||
if (!KubernetesServiceEnabled.value()) { | ||
|
@@ -1384,6 +1431,8 @@ | |
} | ||
|
||
@Override | ||
@ActionEvent(eventType = KubernetesClusterEventTypes.EVENT_KUBERNETES_CLUSTER_DELETE, | ||
eventDescription = "stopping Kubernetes cluster", async = true) | ||
DaanHoogland marked this conversation as resolved.
Show resolved
Hide resolved
|
||
public boolean deleteKubernetesCluster(DeleteKubernetesClusterCmd cmd) throws CloudRuntimeException { | ||
if (!KubernetesServiceEnabled.value()) { | ||
logAndThrow(Level.ERROR, "Kubernetes Service plugin is disabled"); | ||
|
@@ -1526,6 +1575,8 @@ | |
} | ||
|
||
@Override | ||
@ActionEvent(eventType = KubernetesClusterEventTypes.EVENT_KUBERNETES_CLUSTER_SCALE, | ||
eventDescription = "scaling Kubernetes cluster", async = true) | ||
public boolean scaleKubernetesCluster(ScaleKubernetesClusterCmd cmd) throws CloudRuntimeException { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. CallContext.current().setEventDetails("Current min size: ?? New min size: ??"); Can we also set event details here? It would be good to have extra information about the change itself in events. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. will check There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried this. There are too many variables to scale,
|
||
if (!KubernetesServiceEnabled.value()) { | ||
logAndThrow(Level.ERROR, "Kubernetes Service plugin is disabled"); | ||
|
@@ -1549,6 +1600,8 @@ | |
} | ||
|
||
@Override | ||
@ActionEvent(eventType = KubernetesClusterEventTypes.EVENT_KUBERNETES_CLUSTER_UPGRADE, | ||
eventDescription = "upgrading Kubernetes cluster", async = true) | ||
public boolean upgradeKubernetesCluster(UpgradeKubernetesClusterCmd cmd) throws CloudRuntimeException { | ||
if (!KubernetesServiceEnabled.value()) { | ||
logAndThrow(Level.ERROR, "Kubernetes Service plugin is disabled"); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vishesh92 this is not needed as it is done deliberately to allow publishing
Completed
state event forEVENT_KUBERNETES_CLUSTER_CREATE
. Argument passed for the method here is alsoCreateKubernetesClusterCmd
so it will be used only when the cluster is created.