Exit with error on connection failure with kubernetes API.
This commit is contained in:
parent
5ec67ba61a
commit
d85c957b33
4 changed files with 74 additions and 3 deletions
|
|
@ -30,6 +30,7 @@ import java.util.logging.Level;
|
|||
import static org.jdrupes.vmoperator.common.Constants.VM_OP_GROUP;
|
||||
import static org.jdrupes.vmoperator.common.Constants.VM_OP_KIND_VM;
|
||||
import org.jdrupes.vmoperator.common.K8s;
|
||||
import org.jdrupes.vmoperator.manager.events.Exit;
|
||||
import org.jdrupes.vmoperator.manager.events.ModifyVm;
|
||||
import org.jdrupes.vmoperator.manager.events.VmDefChanged;
|
||||
import org.jgrapes.core.Channel;
|
||||
|
|
@ -37,7 +38,6 @@ import org.jgrapes.core.Component;
|
|||
import org.jgrapes.core.annotation.Handler;
|
||||
import org.jgrapes.core.events.HandlingError;
|
||||
import org.jgrapes.core.events.Start;
|
||||
import org.jgrapes.core.events.Stop;
|
||||
import org.jgrapes.util.events.ConfigurationUpdate;
|
||||
|
||||
/**
|
||||
|
|
@ -146,7 +146,7 @@ public class Controller extends Component {
|
|||
logger.severe(() -> "Namespace to control not configured and"
|
||||
+ " no file in kubernetes directory.");
|
||||
event.cancel(true);
|
||||
fire(new Stop());
|
||||
fire(new Exit(2));
|
||||
return;
|
||||
}
|
||||
logger.fine(() -> "Controlling namespace \"" + namespace + "\".");
|
||||
|
|
|
|||
|
|
@ -41,6 +41,7 @@ import org.apache.commons.cli.DefaultParser;
|
|||
import org.apache.commons.cli.Option;
|
||||
import org.apache.commons.cli.Options;
|
||||
import static org.jdrupes.vmoperator.manager.Constants.VM_OP_NAME;
|
||||
import org.jdrupes.vmoperator.manager.events.Exit;
|
||||
import org.jdrupes.vmoperator.util.FsdUtils;
|
||||
import org.jgrapes.core.Channel;
|
||||
import org.jgrapes.core.Component;
|
||||
|
|
@ -82,6 +83,7 @@ public class Manager extends Component {
|
|||
private static Manager app;
|
||||
private String clusterName;
|
||||
private String namespace = "unknown";
|
||||
private static int exitStatus;
|
||||
|
||||
/**
|
||||
* Instantiates a new manager.
|
||||
|
|
@ -224,6 +226,16 @@ public class Manager extends Component {
|
|||
event.stop();
|
||||
}
|
||||
|
||||
/**
|
||||
* On exit.
|
||||
*
|
||||
* @param event the event
|
||||
*/
|
||||
@Handler
|
||||
public void onExit(Exit event) {
|
||||
exitStatus = event.exitStatus();
|
||||
}
|
||||
|
||||
/**
|
||||
* On stop.
|
||||
*
|
||||
|
|
@ -294,6 +306,10 @@ public class Manager extends Component {
|
|||
|
||||
// Start the application
|
||||
Components.start(app);
|
||||
|
||||
// Wait for (regular) termination
|
||||
Components.awaitExhaustion();
|
||||
System.exit(exitStatus);
|
||||
} catch (IOException | InterruptedException
|
||||
| org.apache.commons.cli.ParseException e) {
|
||||
Logger.getLogger(Manager.class.getName()).log(Level.SEVERE, e,
|
||||
|
|
|
|||
|
|
@ -52,6 +52,7 @@ import org.jdrupes.vmoperator.common.K8s;
|
|||
import static org.jdrupes.vmoperator.manager.Constants.APP_NAME;
|
||||
import static org.jdrupes.vmoperator.manager.Constants.VM_OP_KIND_VM;
|
||||
import static org.jdrupes.vmoperator.manager.Constants.VM_OP_NAME;
|
||||
import org.jdrupes.vmoperator.manager.events.Exit;
|
||||
import org.jdrupes.vmoperator.manager.events.VmChannel;
|
||||
import org.jdrupes.vmoperator.manager.events.VmDefChanged;
|
||||
import org.jdrupes.vmoperator.manager.events.VmDefChanged.Type;
|
||||
|
|
@ -105,7 +106,18 @@ public class VmWatcher extends Component {
|
|||
* @throws ApiException
|
||||
*/
|
||||
@Handler(priority = 10)
|
||||
public void onStart(Start event) throws IOException, ApiException {
|
||||
public void onStart(Start event) {
|
||||
try {
|
||||
startWatching();
|
||||
} catch (IOException | ApiException e) {
|
||||
logger.log(Level.SEVERE, e,
|
||||
() -> "Cannot watch VMs, terminating.");
|
||||
event.cancel(true);
|
||||
fire(new Exit(1));
|
||||
}
|
||||
}
|
||||
|
||||
private void startWatching() throws IOException, ApiException {
|
||||
// Get namespace
|
||||
if (namespaceToWatch == null) {
|
||||
var path = Path
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue