Skip to content
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

PAYARA-2297 Support Kubernetes Secret Volumes as Config Source #2203

Merged
merged 6 commits into from
Dec 13, 2017
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ target/
gfbuild.log
/nucleus/payara-modules/requesttracing-core/nbproject/
nb-configuration.xml
/nucleus/payara-modules/nucleus-microprofile/config-service/nbproject/
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ Portions Copyright [2016-2017] [Payara Foundation and/or its affiliates]
<thread-pool name="http-thread-pool" min-thread-pool-size="10" max-thread-pool-size="200" max-queue-size="4096"></thread-pool>
<thread-pool name="thread-pool-1" min-thread-pool-size="2" max-thread-pool-size="200"/>
</thread-pools>
<microprofile-config/>
</config>
</configs>
<property name="administrative.domain.name" value="domain1"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public enum RUNTIME_OPTION {
addjars(true, new SeparatedFilesValidator(true, true, false, true, true)),
rootdir(true, new DirectoryValidator(true, true, true)),
deploymentdir(true, new DirectoryValidator(true, true, false)),
secretsdir(true,new DirectoryValidator(true, true, false)),
domainconfig(true, new FileValidator(true, true, true)),
minhttpthreads(true, new IntegerValidator(1, Integer.MAX_VALUE)),
maxhttpthreads(true, new IntegerValidator(2, Integer.MAX_VALUE)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ public class PayaraMicroImpl implements PayaraMicroBoot {
private String postBootFileName;
private String postDeployFileName;
private RuntimeDirectory runtimeDir = null;
private String secretsDir;

/**
* Runs a Payara Micro server used via java -jar payara-micro.jar
Expand Down Expand Up @@ -984,6 +985,7 @@ public PayaraMicroRuntime bootStrap() throws BootstrapException {
configurePhoneHome();
configureNotificationService();
configureHealthCheck();
configureSecrets();

// Add additional libraries
addLibraries();
Expand Down Expand Up @@ -1300,6 +1302,9 @@ else if (requestTracing[0].matches("\\D+")) {
case postdeploycommandfile:
postDeployFileName = value;
break;
case secretsdir:
secretsDir = value;
break;
default:
break;
}
Expand Down Expand Up @@ -1979,6 +1984,7 @@ private void setArgumentsFromSystemProperties() {
enableRequestTracing = getBooleanProperty("payaramicro.enableRequestTracing");
requestTracingThresholdUnit = getProperty("payaramicro.requestTracingThresholdUnit", "SECONDS");
requestTracingThresholdValue = getLongProperty("payaramicro.requestTracingThresholdValue", 30L);
secretsDir = getProperty("payaramicro.secretsDir");

// Set the rootDir file
String rootDirFileStr = getProperty("payaramicro.rootDir");
Expand Down Expand Up @@ -2102,6 +2108,10 @@ private void packageUberJar() {
if (hzClusterPassword != null) {
props.setProperty("payaramicro.clusterPassword", hzClusterPassword);
}

if (secretsDir != null) {
props.setProperty("payaramicro.secretsDir", secretsDir);
}

props.setProperty("payaramicro.autoBindHttp", Boolean.toString(autoBindHttp));
props.setProperty("payaramicro.autoBindSsl", Boolean.toString(autoBindSsl));
Expand Down Expand Up @@ -2405,4 +2415,10 @@ public void addLibrary(File lib) {
}
}

private void configureSecrets() {
if (secretsDir != null) {
preBootCommands.add(new BootCommand("set", "configs.config.server-config.microprofile-config.secret-dir=" + secretsDir));
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,4 @@ instancegroup=Sets the instance group
group=Sets the instance group
nested=Do not unpack the Nested Jars when booting the server. This is generally slower than unpacking the runtime.
unpackdir=Unpack the Nested Jar runtime jars to the specified directory. Default behaviour is to unpack to java.io.tmpdir
secretsdir=Directory to read secrets files using the Microprofile config api.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ holder.
<name>Microprofile Config Service</name>
<description>Implementation of Microprofile Configuration Service</description>
<packaging>glassfish-jar</packaging>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.15</version>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.glassfish.hk2</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@

/**
* asAdmin command to the get the ordinal for one of the built in Config Sources
*
* @since 4.1.2.173
* @author Steve Millidge (Payara Foundation)
*/
Expand All @@ -65,15 +66,15 @@
@ExecuteOn(RuntimeType.DAS)
@TargetType()
@RestEndpoints({ // creates a REST endpoint needed for integration with the admin interface

@RestEndpoint(configBean = MicroprofileConfigConfiguration.class,
opType = RestEndpoint.OpType.POST, // must be POST as it is doing an update
path = "get-config-ordinal",
description = "Gets the Ordinal of a builtin Config Source")
})
public class GetConfigOrdinal implements AdminCommand {

@Param(optional = true, acceptableValues = "domain,config,server,application,module,cluster,jndi", defaultValue = "domain")
@Param(optional = true, acceptableValues = "domain,config,server,application,module,cluster,jndi,secrets", defaultValue = "domain")
String source;

@Param(optional = true, defaultValue = "server") // if no target is specified it will be the DAS
Expand Down Expand Up @@ -112,10 +113,16 @@ public void execute(AdminCommandContext context) {
case "cluster": {
result = serviceConfig.getClusterOrdinality();
break;
}case "jndi": {
}
case "jndi": {
result = serviceConfig.getJNDIOrdinality();
break;
}
case "secrets": {
result = serviceConfig.getSecretDirOrdinality();
break;
}

}
context.getActionReport().setMessage(result.toString());
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

License header missing here

package fish.payara.nucleus.microprofile.config.admin;

import com.sun.enterprise.config.serverbeans.Config;
import fish.payara.nucleus.microprofile.config.spi.MicroprofileConfigConfiguration;
import javax.inject.Inject;
import org.glassfish.api.Param;
import org.glassfish.api.admin.AdminCommand;
import org.glassfish.api.admin.AdminCommandContext;
import org.glassfish.api.admin.ExecuteOn;
import org.glassfish.api.admin.RestEndpoint;
import org.glassfish.api.admin.RestEndpoints;
import org.glassfish.config.support.TargetType;
import org.glassfish.hk2.api.PerLookup;
import org.glassfish.internal.api.Target;
import org.jvnet.hk2.annotations.Service;

/**
* asAdmin command to the set the directory for the Secrets Dir Config Source
*
* @since 4.1.2.181
* @author Steve Millidge (Payara Foundation)
*/
@Service(name = "get-config-secrets-dir") // the name of the service is the asadmin command name
@PerLookup // this means one instance is created every time the command is run
@ExecuteOn()
@TargetType()
@RestEndpoints({ // creates a REST endpoint needed for integration with the admin interface

@RestEndpoint(configBean = MicroprofileConfigConfiguration.class,
opType = RestEndpoint.OpType.POST, // must be POST as it is doing an update
path = "get-config-secrets-dir",
description = "Gets the Secrets Directory for the Secrets Config Source")
})
public class GetConfigSecretsDirectory implements AdminCommand {

@Param(optional = true, defaultValue = "server") // if no target is specified it will be the DAS
String target;

@Inject
Target targetUtil;

@Override
public void execute(AdminCommandContext context) {
String result = "Not Found";
Config configVal = targetUtil.getConfig(target);
MicroprofileConfigConfiguration serviceConfig = configVal.getExtensionByType(MicroprofileConfigConfiguration.class);
if (serviceConfig != null) {
result = serviceConfig.getSecretDir();
}
context.getActionReport().setMessage(result);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,33 +59,34 @@

/**
* asAdmin command to the set the ordinal for one of the built in Config Sources
*
* @since 4.1.2.173
* @author Steve Millidge (Payara Foundation)
*/
@Service(name = "set-config-ordinal") // the name of the service is the asadmin command name
@PerLookup // this means one instance is created every time the command is run
@ExecuteOn()
@ExecuteOn()
@TargetType()
@RestEndpoints({ // creates a REST endpoint needed for integration with the admin interface
@RestEndpoints({ // creates a REST endpoint needed for integration with the admin interface

@RestEndpoint(configBean = MicroprofileConfigConfiguration.class,
opType = RestEndpoint.OpType.POST, // must be POST as it is doing an update
path = "set-config-ordinal",
description = "Sets the Ordinal of a builtin Config Source")
})
public class SetConfigOrdinal implements AdminCommand {

@Param()
int ordinal;
@Param(optional = true, acceptableValues = "domain,config,server,application,module,cluster,jndi", defaultValue = "domain")

@Param(optional = true, acceptableValues = "domain,config,server,application,module,cluster,jndi,secrets", defaultValue = "domain")
String source;
@Param (optional = true, defaultValue = "server") // if no target is specified it will be the DAS

@Param(optional = true, defaultValue = "server") // if no target is specified it will be the DAS
String target;

@Inject
Target targetUtil;


@Override
public void execute(AdminCommandContext context) {
Expand All @@ -95,11 +96,11 @@ public void execute(AdminCommandContext context) {
try {
// to perform a transaction on the domain.xml you need to use this construct
// see https://github.com/hk2-project/hk2/blob/master/hk2-configuration/persistence/hk2-xml-dom/hk2-config/src/main/java/org/jvnet/hk2/config/ConfigSupport.java
ConfigSupport.apply(new SingleConfigCode<MicroprofileConfigConfiguration>(){
ConfigSupport.apply(new SingleConfigCode<MicroprofileConfigConfiguration>() {
@Override
public Object run(MicroprofileConfigConfiguration config) {
switch(source) {

switch (source) {
case "domain": {
config.setDomainOrdinality(ordinal);
break;
Expand All @@ -111,23 +112,27 @@ public Object run(MicroprofileConfigConfiguration config) {
case "server": {
config.setServerOrdinality(ordinal);
break;
}
}
case "application": {
config.setApplicationOrdinality(ordinal);
break;
}
case "module": {
config.setModuleOrdinality(ordinal);
break;
}
}
case "cluster": {
config.setClusterOrdinality(ordinal);
break;
}
}
case "jndi": {
config.setJNDIOrdinality(ordinal);
break;
}
}
case "secrets": {
config.setSecretDirOrdinality(ordinal);
break;
}
}
return null;
}
Expand All @@ -139,7 +144,7 @@ public Object run(MicroprofileConfigConfiguration config) {
} else {
context.getActionReport().failure(Logger.getLogger(SetConfigOrdinal.class.getName()), "No configuration with name " + target);
}

}

}
Loading