Skip to content

Commit

Permalink
chore: create config from standalone cloudbeat deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
olegsu committed Nov 9, 2022
1 parent ae573e7 commit 697c6bf
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 17 deletions.
20 changes: 20 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}
5 changes: 5 additions & 0 deletions scripts/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}}"
}
33 changes: 16 additions & 17 deletions scripts/remote_replace_cloudbeat.sh
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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

0 comments on commit 697c6bf

Please sign in to comment.