Skip to content

Commit

Permalink
Some fixes after PR review
Browse files Browse the repository at this point in the history
Signed-off-by: Aleksandr Zimin <[email protected]>
  • Loading branch information
AleksZimin committed Mar 14, 2024
1 parent 03e8209 commit 038a0dd
Show file tree
Hide file tree
Showing 13 changed files with 162 additions and 186 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/build_dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ env:
MODULES_MODULE_SOURCE: ${{ vars.DEV_MODULE_SOURCE }}
MODULES_REGISTRY_LOGIN: ${{ vars.DEV_MODULES_REGISTRY_LOGIN }}
MODULES_REGISTRY_PASSWORD: ${{ secrets.DEV_MODULES_REGISTRY_PASSWORD }}
# for ex https://user:[email protected]/group
SOURCE_REPO: "${{ secrets.SOURCE_REPO }}"

on:
pull_request:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/build_prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ env:
MODULES_REGISTRY_LOGIN: ${{ vars.PROD_MODULES_REGISTRY_LOGIN }}
MODULES_REGISTRY_PASSWORD: ${{ secrets.PROD_MODULES_REGISTRY_PASSWORD }}
MODULES_MODULE_TAG: ${{ github.ref_name }}
# for ex https://user:[email protected]/group
SOURCE_REPO: "${{ secrets.SOURCE_REPO }}"

on:
push:
Expand Down
2 changes: 2 additions & 0 deletions .werf/images.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
image: images/{{ $ctx.ImageName }}
context: images/{{ $ctx.ImageName }}
dockerfile: Dockerfile
args:
SOURCE_REPO: {{ env "SOURCE_REPO" | default "https://github.com" }}

{{- /* For werf.inc.yaml render content by providing the ImageName param. */ -}}
{{- else }}
Expand Down
16 changes: 10 additions & 6 deletions images/agent/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ ARG BASE_IMAGE=registry.deckhouse.io/base_images/scratch@sha256:b054705fcc9f2205

#################################
FROM $UBUNTU_UTILS_BUILDER as util-linux-builder
ARG SOURCE_REPO
ARG UTIL_LINUX_VERSION=2.39.3

RUN apt-get update && apt-get install -y \
build-essential \
git \
Expand All @@ -17,12 +20,13 @@ RUN apt-get update && apt-get install -y \
flex \
&& rm -rf /var/lib/apt/lists/*

RUN git clone https://github.com/util-linux/util-linux.git /util-linux

WORKDIR /util-linux
RUN git checkout v2.39.3
RUN ./autogen.sh
RUN ./configure LDFLAGS="-static" --enable-static-programs -disable-shared

RUN git clone ${SOURCE_REPO}/util-linux/util-linux.git . && \
git checkout v${UTIL_LINUX_VERSION} && \
./autogen.sh && \
./configure LDFLAGS="-static" --enable-static-programs -disable-shared

RUN make LDFLAGS="--static" nsenter

#################################
Expand All @@ -42,7 +46,7 @@ RUN GOOS=linux GOARCH=amd64 go build -o sds-node-configurator-agent
#################################
FROM --platform=linux/amd64 $BASE_IMAGE

COPY --from=util-linux-builder /util-linux/nsenter /usr/local/bin/flant/nsenter.static
COPY --from=util-linux-builder /util-linux/nsenter /opt/deckhouse/sds/nsenter.static
COPY --from=agent-builder /go/src/cmd/sds-node-configurator-agent /go/src/cmd/sds-node-configurator-agent

CMD ["/go/src/cmd/sds-node-configurator-agent"]
3 changes: 2 additions & 1 deletion images/agent/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"fmt"
"os"
"os/exec"
"sds-node-configurator/internal"
"sds-node-configurator/pkg/logger"
"time"
)
Expand Down Expand Up @@ -80,7 +81,7 @@ func getMachineId() (string, error) {
args := []string{"-m", "-u", "-i", "-n", "-p", "-t", "1", "cat", "/etc/machine-id"}

var stdout bytes.Buffer
cmd := exec.Command("/usr/local/bin/flant/nsenter.static", args...)
cmd := exec.Command(internal.NSENTERCmd, args...)
cmd.Stdout = &stdout
err := cmd.Run()
if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions images/agent/internal/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ const (
ResizeDelta = "32Mi"
KubernetesApiRequestLimit = 5
KubernetesApiRequestTimeout = 1
NSENTERCmd = "/opt/deckhouse/sds/nsenter.static"
LSBLKCmd = "/opt/deckhouse/sds/lsblk.static"
LVMCmd = "/opt/deckhouse/sds/lvm.static"
)

var (
Expand Down
64 changes: 29 additions & 35 deletions images/agent/pkg/controller/lvm_volume_group_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func RunLVMVolumeGroupWatcherController(
}

createFunc := func(ctx context.Context, e event.CreateEvent, q workqueue.RateLimitingInterface) {
log.Info(fmt.Sprintf("[RunLVMVolumeGroupController] event create LVMVolumeGroup, name: %s", e.Object.GetName()))
log.Info(fmt.Sprintf("[RunLVMVolumeGroupController] Get event CREATE for resource LVMVolumeGroup, name: %s", e.Object.GetName()))

request := reconcile.Request{NamespacedName: types.NamespacedName{Namespace: e.Object.GetNamespace(), Name: e.Object.GetName()}}
shouldRequeue, err := ReconcileLVMVG(ctx, metrics, e.Object.GetName(), e.Object.GetNamespace(), cfg.NodeName, log, cl)
Expand All @@ -92,7 +92,7 @@ func RunLVMVolumeGroupWatcherController(
}

updateFunc := func(ctx context.Context, e event.UpdateEvent, q workqueue.RateLimitingInterface) {
log.Info(fmt.Sprintf("[RunLVMVolumeGroupWatcherController] update LVMVolumeGroupn, name: %s", e.ObjectNew.GetName()))
log.Info(fmt.Sprintf("[RunLVMVolumeGroupWatcherController] Get event UPDATE for resource LVMVolumeGroup, name: %s", e.ObjectNew.GetName()))

newLVG, ok := e.ObjectNew.(*v1alpha1.LvmVolumeGroup)
if !ok {
Expand Down Expand Up @@ -200,39 +200,32 @@ func ReconcileLVMVG(
log.Error(err, fmt.Sprintf("[ReconcileLVMVG] error getLVMVolumeGroup, objectname: %s", objectName))
return true, err
}
validation, status, err := ValidateLVMGroup(ctx, cl, metrics, lvg, objectNameSpace, nodeName)

if lvg == nil {
err = errors.New("nil pointer detected")
log.Error(err, "[ReconcileLVMVG] requested LVMVG group in nil")
return true, err
}

if status.Health == NonOperational {
health := status.Health
var message string
if err != nil {
message = err.Error()
}

log.Error(err, fmt.Sprintf("[ReconcileLVMVG] ValidateLVMGroup, resource name: %s, message: %s", lvg.Name, message))
err = updateLVMVolumeGroupHealthStatus(ctx, cl, metrics, lvg.Name, lvg.Namespace, message, health)
if err != nil {
log.Error(err, fmt.Sprintf("[ReconcileLVMVG] error update LVMVolumeGroup %s", lvg.Name))
return true, err
}
}
isOwnedByNode, status, err := CheckLVMVGNodeOwnership(ctx, cl, metrics, lvg, objectNameSpace, nodeName)

if err != nil {
log.Error(err, fmt.Sprintf("[ReconcileLVMVG] validationLVMGroup failed, resource name: %s", lvg.Name))
return false, err
log.Error(err, fmt.Sprintf("[ReconcileLVMVG] error CheckLVMVGNodeOwnership, resource name: %s", lvg.Name))
if status.Health == NonOperational {
health := status.Health
message := status.Message
log.Error(err, fmt.Sprintf("[ReconcileLVMVG] ValidateLVMGroup, resource name: %s, health: %s, phase: %s, message: %s", lvg.Name, health, status.Phase, message))
err = updateLVMVolumeGroupHealthStatus(ctx, cl, metrics, lvg.Name, lvg.Namespace, message, health)
if err != nil {
log.Error(err, fmt.Sprintf("[ReconcileLVMVG] error update LVMVolumeGroup %s", lvg.Name))
return true, err
}
}
return true, err
}

if validation == false {
err = errors.New("resource validation failed")
log.Error(err, fmt.Sprintf("[ReconcileLVMVG] validation failed for resource, name: %s", lvg.Name))
log.Error(err, fmt.Sprintf("[ReconcileLVMVG] status.Message = %s", status.Message))
return false, err
if !isOwnedByNode {
log.Debug(fmt.Sprintf("[ReconcileLVMVG] resource is not owned by node, name: %s, skip it", lvg.Name))
return false, nil
}

log.Info("[ReconcileLVMVG] validation passed")
Expand Down Expand Up @@ -272,14 +265,14 @@ func ReconcileLVMVG(
}
log.Info(fmt.Sprintf(`[ReconcileLVMVG] event was created for resource, name: %s`, lvg.Name))

existVG, err := ExistVG(lvg.Spec.ActualVGNameOnTheNode, log, metrics)
isVgExist, vg, err := GetVGFromNode(lvg.Spec.ActualVGNameOnTheNode, log, metrics)
if err != nil {
log.Error(err, fmt.Sprintf("[ReconcileLVMVG] error ExistVG, name: %s", lvg.Spec.ActualVGNameOnTheNode))
return true, err
}
if existVG {
log.Debug("[ReconcileLVMVG] tries to update ")
updated, err := UpdateLVMVolumeGroupTagsName(log, metrics, lvg)
if isVgExist {
log.Debug("[ReconcileLVMVG] start UpdateLVMVolumeGroupTagsName for r " + lvg.Name)
updated, err := UpdateLVMVolumeGroupTagsName(log, metrics, vg, lvg)
if err != nil {
log.Error(err, fmt.Sprintf("[ReconcileLVMVG] unable to update VG tags on VG, name: %s", lvg.Spec.ActualVGNameOnTheNode))
return true, err
Expand All @@ -292,16 +285,16 @@ func ReconcileLVMVG(
}

log.Info("[ReconcileLVMVG] validation and choosing the type of operation")
extendPVs, shrinkPVs, err := ValidateTypeLVMGroup(ctx, cl, metrics, lvg, log)
extendPVs, shrinkPVs, err := ValidateOperationTypeLVMGroup(ctx, cl, metrics, lvg, log)
if err != nil {
log.Error(err, fmt.Sprintf("[ReconcileLVMVG] error ValidateTypeLVMGroup, name: %s", lvg.Name))
log.Error(err, fmt.Sprintf("[ReconcileLVMVG] error ValidateOperationTypeLVMGroup, name: %s", lvg.Name))
return true, err
}

if err == nil && extendPVs == nil && shrinkPVs == nil {
log.Warning("[ReconcileLVMVG] ValidateTypeLVMGroup FAIL")
//todo retry and send message
}
// if err == nil && extendPVs == nil && shrinkPVs == nil {
// log.Warning(fmt.Sprintf("[ReconcileLVMVG] ValidateOperationTypeLVMGroup FAIL for resource %s", lvg.Name))
// //todo retry and send message
// }

log.Debug("----- extendPVs list -----")
for _, pvExt := range extendPVs {
Expand Down Expand Up @@ -449,6 +442,7 @@ func ReconcileLVMVG(
log.Error(err, fmt.Sprintf("[ReconcileLVMVG] error CreateEventLVMVolumeGroup, resource name: %s", lvg.Name))
}

log.Debug("[ReconcileLVMVG] Start CreateVGComplex function for resource " + lvg.Name)
err := CreateVGComplex(ctx, cl, metrics, lvg, log)
if err != nil {
log.Error(err, fmt.Sprintf("[ReconcileLVMVG] unable to CreateVGComplex for resource, name: %s", lvg.Name))
Expand Down
Loading

0 comments on commit 038a0dd

Please sign in to comment.