diff --git a/config/config.go b/config/config.go index c5529a89bb..b0695c6bd3 100644 --- a/config/config.go +++ b/config/config.go @@ -77,6 +77,10 @@ var DefaultConfig = Stream{ } func New(cfg *config.C) (Config, error) { + // work with v1 cloudbeat.yml in dev mod + if cfg.HasField("streams") { + return newStandaloneConfig(cfg) + } c := DefaultConfig if err := cfg.Unpack(&c); err != nil { return Config{}, err @@ -99,6 +103,22 @@ func Datastream(namespace string, indexPrefix string) string { return indexPrefix + "-" + namespace } +// stanalone config is used for development flows +// see an example deploy/kustomize/overlays/cloudbeat-vanilla/cloudbeat.yml +func newStandaloneConfig(cfg *config.C) (Config, error) { + c := struct { + Period time.Duration + Streams []Stream + }{4 * time.Hour, []Stream{}} + if err := cfg.Unpack(&c); err != nil { + return Config{}, err + } + return Config{ + Type: InputTypeVanillaK8s, + Stream: c.Streams[0], + }, nil +} + type AwsConfigProvider interface { InitializeAWSConfig(ctx context.Context, cfg aws.ConfigAWS) (awssdk.Config, error) } diff --git a/scripts/common.sh b/scripts/common.sh index b0093a6568..e96c6d620e 100644 --- a/scripts/common.sh +++ b/scripts/common.sh @@ -29,6 +29,11 @@ is_eks() { _kubectl_node_info kubeletVersion | grep "eks" } +get_agent_sha() { + out=$(exec_pod $1 "elastic-agent version --yaml --binary-only") + echo $out | cut -d ":" -f4 | awk '{$1=$1};1'| awk '{ print substr($0, 0, 6) }' +} + _kubectl_node_info() { kubectl get node -o go-template="{{(index .items 0 ).status.nodeInfo.$1}}" } \ No newline at end of file diff --git a/scripts/remote_replace_cloudbeat.sh b/scripts/remote_replace_cloudbeat.sh index 2f688632c8..b7012cd68c 100755 --- a/scripts/remote_replace_cloudbeat.sh +++ b/scripts/remote_replace_cloudbeat.sh @@ -1,6 +1,6 @@ #!/bin/bash -set -euo pipefail +set -eo pipefail # This script uses the kubectl commands in order to ssh into the cluster defined in the host current-context # The script lets you to remotely replace the cloudbeat binary with a file named cloudbeat, located on the host's running directory @@ -12,36 +12,35 @@ if [ "$ARCH" = "amd64" ]; then ARCH="x86_64" fi OS=$(find_target_os) -VERSION="8.6.0" # Read from elsewhere -SNAPSHOT="SNAPSHOT" +VERSION=$(make get-version) -LOCAL_DIR=cloudbeat-$VERSION-$SNAPSHOT-$OS-$ARCH +LOCAL_DIR=cloudbeat-$VERSION-SNAPSHOT-$OS-$ARCH echo "Looking for build distribution: $LOCAL_DIR" tar -xvf build/distributions/$LOCAL_DIR.tar.gz > /dev/null 2>&1 -# cloudbeat.spec.yml should be built in the agent -curl -o cloudbeat.spec.yml https://raw.githubusercontent.com/elastic/elastic-agent/feature-arch-v2/specs/cloudbeat.spec.yml > /dev/null 2>&1 - for P in $(get_agents); do POD=$(echo $P | cut -d '/' -f 2) - out=$(exec_pod $POD "elastic-agent version --yaml --binary-only") - SHA=$(echo $out | cut -d ":" -f4 | awk '{$1=$1};1'| awk '{ print substr($0, 0, 6) }') + SHA=$(get_agent_sha $POD) echo "Found sha=$SHA in pod=$POD" ROOT=/usr/share/elastic-agent/data/elastic-agent-$SHA DEST=$ROOT/components cp_to_pod $POD $LOCAL_DIR/cloudbeat $DEST cp_to_pod $POD $LOCAL_DIR/cloudbeat.yml $DEST/cloudbeat.yml - cp_to_pod $POD cloudbeat.spec.yml $DEST/cloudbeat.spec.yml - BUNDLE="cis_k8s-default" - if [ ! -z "$(is_eks)" ] + # Start with COPY_BUNDLE=true to move also the opa bundle to the agent + # the bundle can be found later in in /usr/share/elastic-agent/data/elastic-agent-{SHA}/run/cloudbeat/{BUNDLE_NAME} + if [[ ! -z "$COPY_BUNDLE" ]] then - BUNDLE="cis_eks-default" + BUNDLE="cis_k8s-default" + if [ ! -z "$(is_eks)" ] + then + BUNDLE="cis_eks-default" + fi + BUNDLE_DIR=$ROOT/run/cloudbeat/$BUNDLE + exec_pod $POD "mkdir -p $BUNDLE_DIR" + cp_to_pod $POD $LOCAL_DIR/bundle.tar.gz $BUNDLE_DIR/bundle.tar.gz fi - BUNDLE_DIR=$ROOT/run/cloudbeat/$BUNDLE - exec_pod $POD "mkdir -p $BUNDLE_DIR" - cp_to_pod $POD $LOCAL_DIR/bundle.tar.gz $BUNDLE_DIR/bundle.tar.gz - echo "Copied all the assets, restarting the agent" + echo "Copied all the assets, restarting the agent $POD" exec_pod $POD "elastic-agent restart" done