Loading deploy_in_kubernetes.sh +23 −14 Original line number Diff line number Diff line Loading @@ -10,7 +10,7 @@ REGISTRY_IMAGE="" #REGISTRY_IMAGE="http://my-container-registry.local/" # Set the list of components you want to build images for, and deploy. COMPONENTS="context device service compute monitoring centralizedattackdetector" COMPONENTS="context device automation service compute monitoring centralizedattackdetector" # Set the tag you want to use for your images. IMAGE_TAG="tf-dev" Loading @@ -18,7 +18,6 @@ IMAGE_TAG="tf-dev" # Set the name of the Kubernetes namespace to deploy to. K8S_NAMESPACE="tf-dev" ######################################################################################################################## # Automated steps start here ######################################################################################################################## Loading @@ -34,10 +33,10 @@ mkdir -p $TMP_MANIFESTS_FOLDER TMP_LOGS_FOLDER="$TMP_FOLDER/logs" mkdir -p $TMP_LOGS_FOLDER # Re-create the namespace to prevent being affected by garbage on it kubectl delete namespace $K8S_NAMESPACE kubectl create namespace $K8S_NAMESPACE printf "\n" for COMPONENT in $COMPONENTS; do echo "Processing '$COMPONENT' component..." Loading @@ -46,32 +45,42 @@ for COMPONENT in $COMPONENTS; do echo " Building Docker image..." BUILD_LOG="$TMP_LOGS_FOLDER/build_${COMPONENT}.log" docker build -t "$IMAGE_NAME" -f ./src/$COMPONENT/Dockerfile ./src/ > $BUILD_LOG if [ "$COMPONENT" == "automation" ]; then docker build -t "$IMAGE_NAME" -f ./src/"$COMPONENT"/Dockerfile ./src/"$COMPONENT"/ > "$BUILD_LOG" else docker build -t "$IMAGE_NAME" -f ./src/"$COMPONENT"/Dockerfile ./src/ > "$BUILD_LOG" fi if [ -n "$REGISTRY_IMAGE" ]; then echo "Pushing Docker image to '$REGISTRY_IMAGE'..." TAG_LOG="$TMP_LOGS_FOLDER/tag_${COMPONENT}.log" docker tag "$IMAGE_NAME" "$IMAGE_URL" > $TAG_LOG docker tag "$IMAGE_NAME" "$IMAGE_URL" > "$TAG_LOG" PUSH_LOG="$TMP_LOGS_FOLDER/push_${COMPONENT}.log" docker push "$IMAGE_URL" > "$PUSH_LOG" fi echo " Adapting manifest file..." echo " Adapting '$COMPONENT' manifest file..." MANIFEST="$TMP_MANIFESTS_FOLDER/${COMPONENT}service.yaml" cp ./manifests/${COMPONENT}service.yaml $MANIFEST cp ./manifests/"${COMPONENT}"service.yaml "$MANIFEST" VERSION=$(grep -i "${GITLAB_REPO_URL}/${COMPONENT}:" "$MANIFEST" | cut -d ":" -f3) if [ -n "$REGISTRY_IMAGE" ]; then sed -E -i "s#image: $GITLAB_REPO_URL/$COMPONENT:latest#image: $IMAGE_URL#g" $MANIFEST sed -E -i "s#imagePullPolicy: .*#imagePullPolicy: Always#g" $MANIFEST sed -E -i "s#image: $GITLAB_REPO_URL/$COMPONENT:${VERSION}#image: $IMAGE_URL#g" "$MANIFEST" sed -E -i "s#imagePullPolicy: .*#imagePullPolicy: Always#g" "$MANIFEST" else sed -E -i "s#image: $GITLAB_REPO_URL/$COMPONENT:latest#image: $IMAGE_NAME#g" $MANIFEST sed -E -i "s#imagePullPolicy: .*#imagePullPolicy: Never#g" $MANIFEST sed -E -i "s#image: $GITLAB_REPO_URL/$COMPONENT:${VERSION}#image: $IMAGE_NAME#g" "$MANIFEST" sed -E -i "s#imagePullPolicy: .*#imagePullPolicy: Never#g" "$MANIFEST" fi echo " Deploying to Kubernetes..." echo " Deploying '$COMPONENT' component to Kubernetes..." DEPLOY_LOG="$TMP_LOGS_FOLDER/push_${COMPONENT}.log" kubectl --namespace $K8S_NAMESPACE apply -f $MANIFEST > $DEPLOY_LOG kubectl --namespace $K8S_NAMESPACE apply -f "$MANIFEST" > "$DEPLOY_LOG" printf "\n" done kubectl --namespace $K8S_NAMESPACE get all Loading proto/automation.proto +11 −6 Original line number Diff line number Diff line Loading @@ -10,7 +10,7 @@ service AutomationService { rpc ZtpAdd(DeviceRole) returns (DeviceRoleState) {} rpc ZtpUpdate(DeviceRole) returns (DeviceRoleState) {} rpc ZtpDelete(DeviceRole) returns (DeviceRoleState) {} rpc ZtpDeleteAllByDeviceId(context.DeviceId) returns (DeviceRoleState) {} rpc ZtpDeleteAll(Empty) returns (DeviceDeletionResult) {} } enum DeviceRoleType { Loading Loading @@ -39,12 +39,17 @@ message DeviceRoleState { ZtpDeviceState devRoleState = 2; } message DeviceDeletionResult { repeated bool deleted = 1; } message Empty {} enum ZtpDeviceState { PLANNED = 0; POTENCIAL_AVAILABLE = 1; POTENCIAL_BUSY = 2; INSTALLED = 3; PENDING_REMOVAL = 4; ZTP_DEV_STATE_UNDEFINED = 0; ZTP_DEV_STATE_CREATED = 1; ZTP_DEV_STATE_UPDATED = 2; ZTP_DEV_STATE_DELETED = 3; } src/automation/Dockerfile 0 → 120000 +1 −0 Original line number Diff line number Diff line src/main/docker/Dockerfile.multistage.jvm No newline at end of file src/automation/src/main/java/eu/teraflow/automation/AutomationConfiguration.java 0 → 100644 +9 −0 Original line number Diff line number Diff line package eu.teraflow.automation; import io.smallrye.config.ConfigMapping; @ConfigMapping(prefix = "automation") public interface AutomationConfiguration { boolean shouldSubscribeToContextComponent(); } src/automation/src/main/java/eu/teraflow/automation/AutomationGatewayImpl.java +6 −24 Original line number Diff line number Diff line Loading @@ -4,9 +4,6 @@ import automation.Automation; import context.ContextOuterClass; import eu.teraflow.automation.device.model.DeviceId; import eu.teraflow.automation.device.model.Uuid; import eu.teraflow.automation.model.DeviceRole; import eu.teraflow.automation.model.DeviceRoleId; import eu.teraflow.automation.model.DeviceRoleType; import io.quarkus.grpc.GrpcService; import io.smallrye.mutiny.Uni; import javax.inject.Inject; Loading Loading @@ -36,7 +33,7 @@ public class AutomationGatewayImpl implements AutomationGateway { @Override public Uni<Automation.DeviceRoleState> ztpAdd(Automation.DeviceRole request) { automationService.ztpAdd(getDeviceRole(request)); automationService.addDevice(getDeviceId(request.getDevRoleId().getDevId())); return Uni.createFrom() .item( Loading Loading @@ -67,29 +64,14 @@ public class AutomationGatewayImpl implements AutomationGateway { } @Override public Uni<Automation.DeviceRoleState> ztpDeleteAllByDeviceId( ContextOuterClass.DeviceId request) { return Uni.createFrom().item(() -> Automation.DeviceRoleState.newBuilder().build()); public Uni<Automation.DeviceDeletionResult> ztpDeleteAll(Automation.Empty empty) { return Uni.createFrom().item(() -> Automation.DeviceDeletionResult.newBuilder().build()); } private DeviceRole getDeviceRole(Automation.DeviceRole deviceRole) { final var OutDeviceId = deviceRole.getDevRoleId().getDevId().getDeviceUuid(); Uuid uuid = new Uuid(OutDeviceId.getUuid()); DeviceId deviceId = new DeviceId(uuid); private DeviceId getDeviceId(ContextOuterClass.DeviceId serializedDeviceId) { DeviceRoleId deviceRoleId = new DeviceRoleId(uuid, deviceId); Uuid uuid = new Uuid(serializedDeviceId.getDeviceUuid().getUuid()); final var deviceRoleType = deviceRole.getDevRoleType(); if (deviceRoleType == Automation.DeviceRoleType.DEV_OPS) { return new DeviceRole(deviceRoleId, DeviceRoleType.DEV_OPS); } else if (deviceRoleType == Automation.DeviceRoleType.DEV_CONF) { return new DeviceRole(deviceRoleId, DeviceRoleType.DEV_CONF); } else if (deviceRoleType == Automation.DeviceRoleType.NONE) { return new DeviceRole(deviceRoleId, DeviceRoleType.NONE); } else { return new DeviceRole(deviceRoleId, DeviceRoleType.PIPELINE_CONF); } return new DeviceId(uuid); } } Loading
deploy_in_kubernetes.sh +23 −14 Original line number Diff line number Diff line Loading @@ -10,7 +10,7 @@ REGISTRY_IMAGE="" #REGISTRY_IMAGE="http://my-container-registry.local/" # Set the list of components you want to build images for, and deploy. COMPONENTS="context device service compute monitoring centralizedattackdetector" COMPONENTS="context device automation service compute monitoring centralizedattackdetector" # Set the tag you want to use for your images. IMAGE_TAG="tf-dev" Loading @@ -18,7 +18,6 @@ IMAGE_TAG="tf-dev" # Set the name of the Kubernetes namespace to deploy to. K8S_NAMESPACE="tf-dev" ######################################################################################################################## # Automated steps start here ######################################################################################################################## Loading @@ -34,10 +33,10 @@ mkdir -p $TMP_MANIFESTS_FOLDER TMP_LOGS_FOLDER="$TMP_FOLDER/logs" mkdir -p $TMP_LOGS_FOLDER # Re-create the namespace to prevent being affected by garbage on it kubectl delete namespace $K8S_NAMESPACE kubectl create namespace $K8S_NAMESPACE printf "\n" for COMPONENT in $COMPONENTS; do echo "Processing '$COMPONENT' component..." Loading @@ -46,32 +45,42 @@ for COMPONENT in $COMPONENTS; do echo " Building Docker image..." BUILD_LOG="$TMP_LOGS_FOLDER/build_${COMPONENT}.log" docker build -t "$IMAGE_NAME" -f ./src/$COMPONENT/Dockerfile ./src/ > $BUILD_LOG if [ "$COMPONENT" == "automation" ]; then docker build -t "$IMAGE_NAME" -f ./src/"$COMPONENT"/Dockerfile ./src/"$COMPONENT"/ > "$BUILD_LOG" else docker build -t "$IMAGE_NAME" -f ./src/"$COMPONENT"/Dockerfile ./src/ > "$BUILD_LOG" fi if [ -n "$REGISTRY_IMAGE" ]; then echo "Pushing Docker image to '$REGISTRY_IMAGE'..." TAG_LOG="$TMP_LOGS_FOLDER/tag_${COMPONENT}.log" docker tag "$IMAGE_NAME" "$IMAGE_URL" > $TAG_LOG docker tag "$IMAGE_NAME" "$IMAGE_URL" > "$TAG_LOG" PUSH_LOG="$TMP_LOGS_FOLDER/push_${COMPONENT}.log" docker push "$IMAGE_URL" > "$PUSH_LOG" fi echo " Adapting manifest file..." echo " Adapting '$COMPONENT' manifest file..." MANIFEST="$TMP_MANIFESTS_FOLDER/${COMPONENT}service.yaml" cp ./manifests/${COMPONENT}service.yaml $MANIFEST cp ./manifests/"${COMPONENT}"service.yaml "$MANIFEST" VERSION=$(grep -i "${GITLAB_REPO_URL}/${COMPONENT}:" "$MANIFEST" | cut -d ":" -f3) if [ -n "$REGISTRY_IMAGE" ]; then sed -E -i "s#image: $GITLAB_REPO_URL/$COMPONENT:latest#image: $IMAGE_URL#g" $MANIFEST sed -E -i "s#imagePullPolicy: .*#imagePullPolicy: Always#g" $MANIFEST sed -E -i "s#image: $GITLAB_REPO_URL/$COMPONENT:${VERSION}#image: $IMAGE_URL#g" "$MANIFEST" sed -E -i "s#imagePullPolicy: .*#imagePullPolicy: Always#g" "$MANIFEST" else sed -E -i "s#image: $GITLAB_REPO_URL/$COMPONENT:latest#image: $IMAGE_NAME#g" $MANIFEST sed -E -i "s#imagePullPolicy: .*#imagePullPolicy: Never#g" $MANIFEST sed -E -i "s#image: $GITLAB_REPO_URL/$COMPONENT:${VERSION}#image: $IMAGE_NAME#g" "$MANIFEST" sed -E -i "s#imagePullPolicy: .*#imagePullPolicy: Never#g" "$MANIFEST" fi echo " Deploying to Kubernetes..." echo " Deploying '$COMPONENT' component to Kubernetes..." DEPLOY_LOG="$TMP_LOGS_FOLDER/push_${COMPONENT}.log" kubectl --namespace $K8S_NAMESPACE apply -f $MANIFEST > $DEPLOY_LOG kubectl --namespace $K8S_NAMESPACE apply -f "$MANIFEST" > "$DEPLOY_LOG" printf "\n" done kubectl --namespace $K8S_NAMESPACE get all Loading
proto/automation.proto +11 −6 Original line number Diff line number Diff line Loading @@ -10,7 +10,7 @@ service AutomationService { rpc ZtpAdd(DeviceRole) returns (DeviceRoleState) {} rpc ZtpUpdate(DeviceRole) returns (DeviceRoleState) {} rpc ZtpDelete(DeviceRole) returns (DeviceRoleState) {} rpc ZtpDeleteAllByDeviceId(context.DeviceId) returns (DeviceRoleState) {} rpc ZtpDeleteAll(Empty) returns (DeviceDeletionResult) {} } enum DeviceRoleType { Loading Loading @@ -39,12 +39,17 @@ message DeviceRoleState { ZtpDeviceState devRoleState = 2; } message DeviceDeletionResult { repeated bool deleted = 1; } message Empty {} enum ZtpDeviceState { PLANNED = 0; POTENCIAL_AVAILABLE = 1; POTENCIAL_BUSY = 2; INSTALLED = 3; PENDING_REMOVAL = 4; ZTP_DEV_STATE_UNDEFINED = 0; ZTP_DEV_STATE_CREATED = 1; ZTP_DEV_STATE_UPDATED = 2; ZTP_DEV_STATE_DELETED = 3; }
src/automation/Dockerfile 0 → 120000 +1 −0 Original line number Diff line number Diff line src/main/docker/Dockerfile.multistage.jvm No newline at end of file
src/automation/src/main/java/eu/teraflow/automation/AutomationConfiguration.java 0 → 100644 +9 −0 Original line number Diff line number Diff line package eu.teraflow.automation; import io.smallrye.config.ConfigMapping; @ConfigMapping(prefix = "automation") public interface AutomationConfiguration { boolean shouldSubscribeToContextComponent(); }
src/automation/src/main/java/eu/teraflow/automation/AutomationGatewayImpl.java +6 −24 Original line number Diff line number Diff line Loading @@ -4,9 +4,6 @@ import automation.Automation; import context.ContextOuterClass; import eu.teraflow.automation.device.model.DeviceId; import eu.teraflow.automation.device.model.Uuid; import eu.teraflow.automation.model.DeviceRole; import eu.teraflow.automation.model.DeviceRoleId; import eu.teraflow.automation.model.DeviceRoleType; import io.quarkus.grpc.GrpcService; import io.smallrye.mutiny.Uni; import javax.inject.Inject; Loading Loading @@ -36,7 +33,7 @@ public class AutomationGatewayImpl implements AutomationGateway { @Override public Uni<Automation.DeviceRoleState> ztpAdd(Automation.DeviceRole request) { automationService.ztpAdd(getDeviceRole(request)); automationService.addDevice(getDeviceId(request.getDevRoleId().getDevId())); return Uni.createFrom() .item( Loading Loading @@ -67,29 +64,14 @@ public class AutomationGatewayImpl implements AutomationGateway { } @Override public Uni<Automation.DeviceRoleState> ztpDeleteAllByDeviceId( ContextOuterClass.DeviceId request) { return Uni.createFrom().item(() -> Automation.DeviceRoleState.newBuilder().build()); public Uni<Automation.DeviceDeletionResult> ztpDeleteAll(Automation.Empty empty) { return Uni.createFrom().item(() -> Automation.DeviceDeletionResult.newBuilder().build()); } private DeviceRole getDeviceRole(Automation.DeviceRole deviceRole) { final var OutDeviceId = deviceRole.getDevRoleId().getDevId().getDeviceUuid(); Uuid uuid = new Uuid(OutDeviceId.getUuid()); DeviceId deviceId = new DeviceId(uuid); private DeviceId getDeviceId(ContextOuterClass.DeviceId serializedDeviceId) { DeviceRoleId deviceRoleId = new DeviceRoleId(uuid, deviceId); Uuid uuid = new Uuid(serializedDeviceId.getDeviceUuid().getUuid()); final var deviceRoleType = deviceRole.getDevRoleType(); if (deviceRoleType == Automation.DeviceRoleType.DEV_OPS) { return new DeviceRole(deviceRoleId, DeviceRoleType.DEV_OPS); } else if (deviceRoleType == Automation.DeviceRoleType.DEV_CONF) { return new DeviceRole(deviceRoleId, DeviceRoleType.DEV_CONF); } else if (deviceRoleType == Automation.DeviceRoleType.NONE) { return new DeviceRole(deviceRoleId, DeviceRoleType.NONE); } else { return new DeviceRole(deviceRoleId, DeviceRoleType.PIPELINE_CONF); } return new DeviceId(uuid); } }