You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@brooklyn.apache.org by GitBox <gi...@apache.org> on 2022/06/20 16:17:32 UTC
[GitHub] [brooklyn-server] iuliana opened a new pull request, #1321: Adding Kubectl Task factory, Docker effector and Docker Sensor
iuliana opened a new pull request, #1321:
URL: https://github.com/apache/brooklyn-server/pull/1321
**What**
`kubectl` task factory that allows blueprint designers to externalize effectors and sensors to containers run on a Kubernetes cluster.
**Why**
Because it is practical and higly customizable.
**Testing**
Sample blueprints are provides. Also tests for sensor, effector and task factory.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@brooklyn.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [brooklyn-server] iuliana commented on a diff in pull request #1321: Adding Kubectl Task factory, Docker effector and Docker Sensor
Posted by GitBox <gi...@apache.org>.
iuliana commented on code in PR #1321:
URL: https://github.com/apache/brooklyn-server/pull/1321#discussion_r902397724
##########
software/base/src/main/java/org/apache/brooklyn/tasks/kubectl/ContainerTaskFactory.java:
##########
@@ -0,0 +1,133 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.brooklyn.tasks.kubectl;
+
+import com.google.common.collect.Lists;
+import org.apache.brooklyn.api.mgmt.Task;
+import org.apache.brooklyn.api.mgmt.TaskFactory;
+import org.apache.brooklyn.core.entity.BrooklynConfigKeys;
+import org.apache.brooklyn.core.entity.EntityInitializers;
+import org.apache.brooklyn.core.mgmt.BrooklynTaskTags;
+import org.apache.brooklyn.util.collections.MutableMap;
+import org.apache.brooklyn.util.core.config.ConfigBag;
+import org.apache.brooklyn.util.core.task.TaskBuilder;
+import org.apache.brooklyn.util.core.task.Tasks;
+import org.apache.brooklyn.util.core.task.system.ProcessTaskStub;
+import org.apache.brooklyn.util.core.task.system.ProcessTaskWrapper;
+import org.apache.brooklyn.util.core.task.system.internal.SystemProcessTaskFactory;
+import org.apache.brooklyn.util.text.Strings;
+
+import java.util.List;
+import java.util.Map;
+
+import static org.apache.brooklyn.tasks.kubectl.ContainerCommons.*;
+
+public class ContainerTaskFactory<T extends ContainerTaskFactory<T,RET>,RET> implements TaskFactory<Task<RET>> {
+
+ protected String summary;
+ protected String tag = "";
+ protected final ConfigBag config = ConfigBag.newInstance();
+
+ @Override
+ public Task<RET> newTask() {
+ ConfigBag configBag = this.config;
+
+ List<String> commandsCfg = EntityInitializers.resolve(configBag, COMMANDS);
+ List<String> argumentsCfg = EntityInitializers.resolve(configBag, ARGUMENTS);
+ String containerImage = EntityInitializers.resolve(configBag, CONTAINER_IMAGE);
+ String containerNameFromCfg = EntityInitializers.resolve(configBag, CONTAINER_NAME);
+ Boolean devMode = EntityInitializers.resolve(configBag, DEV_MODE);
+
+ if(Strings.isBlank(containerImage)) {
+ throw new IllegalStateException("You must specify containerImage when using " + this.getClass().getSimpleName());
+ }
+
+
+ final String containerName = (Strings.isBlank(containerNameFromCfg)
+ ? ( (Strings.isNonBlank(this.tag) ? this.tag + "-" : "").concat(containerImage).concat("-").concat(Strings.makeRandomId(10)))
+ : containerNameFromCfg).replace(" ", "-").replace("/", "-").toLowerCase();
+
+ final String jobYamlLocation = new JobBuilder()
+ .withImage(containerImage)
+ .withName(containerName)
+ .withArgs(argumentsCfg)
+ .withEnv(EntityInitializers.resolve(configBag, BrooklynConfigKeys.SHELL_ENVIRONMENT))
+ .withCommands(Lists.newArrayList(commandsCfg))
+ .build();
+
+
+ Task<String> runCommandsTask = buildKubeTask(configBag, "Submit job", String.format(JOBS_CREATE_CMD,jobYamlLocation)).asTask();
+ Task<String> waitTask = buildKubeTask(configBag, "Wait For Completion", String.format(JOBS_FEED_CMD,containerName)).asTask();
+ if(!devMode) {
+ BrooklynTaskTags.addTagDynamically(waitTask, BrooklynTaskTags.INESSENTIAL_TASK);
+ }
+
+ TaskBuilder<RET> taskBuilder = Tasks.<RET>builder()
+ .displayName(this.summary)
+ .add(buildKubeTask(configBag, "Set Up and Run",
+ String.format(NAMESPACE_CREATE_CMD,containerName),
+ String.format(NAMESPACE_SET_CMD,containerName)))
+ .add(runCommandsTask)
+ .add(waitTask)
+ .add(buildKubeTask(configBag, "Retrieve Output", String.format(JOBS_LOGS_CMD,containerName)));
+
+ if(!devMode) {
Review Comment:
@ahgittin renamed to `keepContainerForDebugging`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@brooklyn.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [brooklyn-server] ahgittin commented on a diff in pull request #1321: Adding Kubectl Task factory, Docker effector and Docker Sensor
Posted by GitBox <gi...@apache.org>.
ahgittin commented on code in PR #1321:
URL: https://github.com/apache/brooklyn-server/pull/1321#discussion_r907333811
##########
software/base/src/main/java/org/apache/brooklyn/tasks/kubectl/ContainerCommons.java:
##########
@@ -34,6 +38,10 @@ public interface ContainerCommons {
ConfigKey<List> COMMANDS = ConfigKeys.newConfigKey(List.class,"commands", "Commands to execute for container", Lists.newArrayList());
ConfigKey<List> ARGUMENTS = ConfigKeys.newConfigKey(List.class,"args", "Arguments to execute for container", Lists.newArrayList());
+ ConfigKey<String> WORKING_DIR = ConfigKeys.newStringConfigKey("workingDir", "Location where the container commands are executed");
+ ConfigKey<List<Map<String,String>>> VOLUME_MOUNTS = ConfigKeys.newConfigKey("volumeMounts", "Configuration to mount a volume into a container.", Lists.newArrayList());
Review Comment:
Better to use `SetConfigKey.builder(new TypeToken<Map<String,String>>() {}, "volumeMounts").description(...).build()` -- we prefer sets to lists (for legacy reasons where we used hazelcast for sharing objects between instances; we don't do this any more but sets are easier to work with).
And allow `null` rather than set an empty default value.
And finally there are a couple of double spaces in the description.
Also `VOLUMES` (for the first two points above).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@brooklyn.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [brooklyn-server] iuliana merged pull request #1321: Adding Kubectl Task factory, Docker effector and Docker Sensor
Posted by GitBox <gi...@apache.org>.
iuliana merged PR #1321:
URL: https://github.com/apache/brooklyn-server/pull/1321
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@brooklyn.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [brooklyn-server] ahgittin commented on pull request #1321: Adding Kubectl Task factory, Docker effector and Docker Sensor
Posted by GitBox <gi...@apache.org>.
ahgittin commented on PR #1321:
URL: https://github.com/apache/brooklyn-server/pull/1321#issuecomment-1167295819
one minor comment, otherwise LGTM
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@brooklyn.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [brooklyn-server] ahgittin commented on a diff in pull request #1321: Adding Kubectl Task factory, Docker effector and Docker Sensor
Posted by GitBox <gi...@apache.org>.
ahgittin commented on code in PR #1321:
URL: https://github.com/apache/brooklyn-server/pull/1321#discussion_r902380479
##########
software/base/src/main/java/org/apache/brooklyn/tasks/kubectl/ContainerTaskFactory.java:
##########
@@ -0,0 +1,133 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.brooklyn.tasks.kubectl;
+
+import com.google.common.collect.Lists;
+import org.apache.brooklyn.api.mgmt.Task;
+import org.apache.brooklyn.api.mgmt.TaskFactory;
+import org.apache.brooklyn.core.entity.BrooklynConfigKeys;
+import org.apache.brooklyn.core.entity.EntityInitializers;
+import org.apache.brooklyn.core.mgmt.BrooklynTaskTags;
+import org.apache.brooklyn.util.collections.MutableMap;
+import org.apache.brooklyn.util.core.config.ConfigBag;
+import org.apache.brooklyn.util.core.task.TaskBuilder;
+import org.apache.brooklyn.util.core.task.Tasks;
+import org.apache.brooklyn.util.core.task.system.ProcessTaskStub;
+import org.apache.brooklyn.util.core.task.system.ProcessTaskWrapper;
+import org.apache.brooklyn.util.core.task.system.internal.SystemProcessTaskFactory;
+import org.apache.brooklyn.util.text.Strings;
+
+import java.util.List;
+import java.util.Map;
+
+import static org.apache.brooklyn.tasks.kubectl.ContainerCommons.*;
+
+public class ContainerTaskFactory<T extends ContainerTaskFactory<T,RET>,RET> implements TaskFactory<Task<RET>> {
+
+ protected String summary;
+ protected String tag = "";
+ protected final ConfigBag config = ConfigBag.newInstance();
+
+ @Override
+ public Task<RET> newTask() {
+ ConfigBag configBag = this.config;
+
+ List<String> commandsCfg = EntityInitializers.resolve(configBag, COMMANDS);
+ List<String> argumentsCfg = EntityInitializers.resolve(configBag, ARGUMENTS);
+ String containerImage = EntityInitializers.resolve(configBag, CONTAINER_IMAGE);
+ String containerNameFromCfg = EntityInitializers.resolve(configBag, CONTAINER_NAME);
+ Boolean devMode = EntityInitializers.resolve(configBag, DEV_MODE);
+
+ if(Strings.isBlank(containerImage)) {
+ throw new IllegalStateException("You must specify containerImage when using " + this.getClass().getSimpleName());
+ }
+
+
+ final String containerName = (Strings.isBlank(containerNameFromCfg)
+ ? ( (Strings.isNonBlank(this.tag) ? this.tag + "-" : "").concat(containerImage).concat("-").concat(Strings.makeRandomId(10)))
+ : containerNameFromCfg).replace(" ", "-").replace("/", "-").toLowerCase();
+
+ final String jobYamlLocation = new JobBuilder()
+ .withImage(containerImage)
+ .withName(containerName)
+ .withArgs(argumentsCfg)
+ .withEnv(EntityInitializers.resolve(configBag, BrooklynConfigKeys.SHELL_ENVIRONMENT))
+ .withCommands(Lists.newArrayList(commandsCfg))
+ .build();
+
+
+ Task<String> runCommandsTask = buildKubeTask(configBag, "Submit job", String.format(JOBS_CREATE_CMD,jobYamlLocation)).asTask();
+ Task<String> waitTask = buildKubeTask(configBag, "Wait For Completion", String.format(JOBS_FEED_CMD,containerName)).asTask();
+ if(!devMode) {
+ BrooklynTaskTags.addTagDynamically(waitTask, BrooklynTaskTags.INESSENTIAL_TASK);
+ }
+
+ TaskBuilder<RET> taskBuilder = Tasks.<RET>builder()
+ .displayName(this.summary)
+ .add(buildKubeTask(configBag, "Set Up and Run",
+ String.format(NAMESPACE_CREATE_CMD,containerName),
+ String.format(NAMESPACE_SET_CMD,containerName)))
+ .add(runCommandsTask)
+ .add(waitTask)
+ .add(buildKubeTask(configBag, "Retrieve Output", String.format(JOBS_LOGS_CMD,containerName)));
+
+ if(!devMode) {
Review Comment:
I would rename `devMode` as `keepContainersForDebugging` with an additional comment in description that if true, the operator must take responsibility for cleaning up containers. It should be easy enough, e.g. a cron job which deletes finished containers matching the brooklyn container naming convention, no?
So I don't think we yet need a global property to forbid this, though that could be an enhancement in future.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@brooklyn.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [brooklyn-server] jcabrerizo commented on a diff in pull request #1321: Adding Kubectl Task factory, Docker effector and Docker Sensor
Posted by GitBox <gi...@apache.org>.
jcabrerizo commented on code in PR #1321:
URL: https://github.com/apache/brooklyn-server/pull/1321#discussion_r902323276
##########
software/base/src/main/java/org/apache/brooklyn/tasks/kubectl/ContainerTaskFactory.java:
##########
@@ -0,0 +1,133 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.brooklyn.tasks.kubectl;
+
+import com.google.common.collect.Lists;
+import org.apache.brooklyn.api.mgmt.Task;
+import org.apache.brooklyn.api.mgmt.TaskFactory;
+import org.apache.brooklyn.core.entity.BrooklynConfigKeys;
+import org.apache.brooklyn.core.entity.EntityInitializers;
+import org.apache.brooklyn.core.mgmt.BrooklynTaskTags;
+import org.apache.brooklyn.util.collections.MutableMap;
+import org.apache.brooklyn.util.core.config.ConfigBag;
+import org.apache.brooklyn.util.core.task.TaskBuilder;
+import org.apache.brooklyn.util.core.task.Tasks;
+import org.apache.brooklyn.util.core.task.system.ProcessTaskStub;
+import org.apache.brooklyn.util.core.task.system.ProcessTaskWrapper;
+import org.apache.brooklyn.util.core.task.system.internal.SystemProcessTaskFactory;
+import org.apache.brooklyn.util.text.Strings;
+
+import java.util.List;
+import java.util.Map;
+
+import static org.apache.brooklyn.tasks.kubectl.ContainerCommons.*;
+
+public class ContainerTaskFactory<T extends ContainerTaskFactory<T,RET>,RET> implements TaskFactory<Task<RET>> {
+
+ protected String summary;
+ protected String tag = "";
+ protected final ConfigBag config = ConfigBag.newInstance();
+
+ @Override
+ public Task<RET> newTask() {
+ ConfigBag configBag = this.config;
+
+ List<String> commandsCfg = EntityInitializers.resolve(configBag, COMMANDS);
+ List<String> argumentsCfg = EntityInitializers.resolve(configBag, ARGUMENTS);
+ String containerImage = EntityInitializers.resolve(configBag, CONTAINER_IMAGE);
+ String containerNameFromCfg = EntityInitializers.resolve(configBag, CONTAINER_NAME);
+ Boolean devMode = EntityInitializers.resolve(configBag, DEV_MODE);
+
+ if(Strings.isBlank(containerImage)) {
+ throw new IllegalStateException("You must specify containerImage when using " + this.getClass().getSimpleName());
+ }
+
+
+ final String containerName = (Strings.isBlank(containerNameFromCfg)
+ ? ( (Strings.isNonBlank(this.tag) ? this.tag + "-" : "").concat(containerImage).concat("-").concat(Strings.makeRandomId(10)))
+ : containerNameFromCfg).replace(" ", "-").replace("/", "-").toLowerCase();
+
+ final String jobYamlLocation = new JobBuilder()
+ .withImage(containerImage)
+ .withName(containerName)
+ .withArgs(argumentsCfg)
+ .withEnv(EntityInitializers.resolve(configBag, BrooklynConfigKeys.SHELL_ENVIRONMENT))
+ .withCommands(Lists.newArrayList(commandsCfg))
+ .build();
+
+
+ Task<String> runCommandsTask = buildKubeTask(configBag, "Submit job", String.format(JOBS_CREATE_CMD,jobYamlLocation)).asTask();
+ Task<String> waitTask = buildKubeTask(configBag, "Wait For Completion", String.format(JOBS_FEED_CMD,containerName)).asTask();
+ if(!devMode) {
+ BrooklynTaskTags.addTagDynamically(waitTask, BrooklynTaskTags.INESSENTIAL_TASK);
+ }
+
+ TaskBuilder<RET> taskBuilder = Tasks.<RET>builder()
+ .displayName(this.summary)
+ .add(buildKubeTask(configBag, "Set Up and Run",
+ String.format(NAMESPACE_CREATE_CMD,containerName),
+ String.format(NAMESPACE_SET_CMD,containerName)))
+ .add(runCommandsTask)
+ .add(waitTask)
+ .add(buildKubeTask(configBag, "Retrieve Output", String.format(JOBS_LOGS_CMD,containerName)));
+
+ if(!devMode) {
Review Comment:
My feeling about `devMode` is it could be a risk allow not to remove a sensor container based on a blueprint parameter. It will create a new container periodically and if is not removed will consume resources and pull down the kubernetes cluster eventually.
Keeping that property in the `booklyn.cfg` file let the Brooklyn admin to allow or not that behaviour at the server level instead the blueprints and I think is safer -> dev server allow dev blueprints in a dev kubernetes cluster, but the production server doesn't
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@brooklyn.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [brooklyn-server] iuliana commented on a diff in pull request #1321: Adding Kubectl Task factory, Docker effector and Docker Sensor
Posted by GitBox <gi...@apache.org>.
iuliana commented on code in PR #1321:
URL: https://github.com/apache/brooklyn-server/pull/1321#discussion_r907433074
##########
software/base/src/main/java/org/apache/brooklyn/tasks/kubectl/ContainerCommons.java:
##########
@@ -34,6 +38,10 @@ public interface ContainerCommons {
ConfigKey<List> COMMANDS = ConfigKeys.newConfigKey(List.class,"commands", "Commands to execute for container", Lists.newArrayList());
ConfigKey<List> ARGUMENTS = ConfigKeys.newConfigKey(List.class,"args", "Arguments to execute for container", Lists.newArrayList());
+ ConfigKey<String> WORKING_DIR = ConfigKeys.newStringConfigKey("workingDir", "Location where the container commands are executed");
+ ConfigKey<List<Map<String,String>>> VOLUME_MOUNTS = ConfigKeys.newConfigKey("volumeMounts", "Configuration to mount a volume into a container.", Lists.newArrayList());
Review Comment:
Addressed comments in the most recent commit. @ahgittin
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@brooklyn.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org