Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v2] Delete unused code from refactor #777

Merged
merged 23 commits into from
Jul 26, 2022
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
6b66b73
Add runtime for command v2 components.
blakerouse Jun 30, 2022
148b1dd
Fix imports.
blakerouse Jun 30, 2022
6f0d148
Add tests for watching checkins.
blakerouse Jun 30, 2022
35845b2
Fix lint and move checkin period to a configurable timeout.
blakerouse Jun 30, 2022
a60ae17
Fix tests now that checkin timeout needs to be defined.
blakerouse Jun 30, 2022
a40830c
Fix code review and lint.
blakerouse Jul 13, 2022
a00db54
Work on actually running the v2 runtime.
blakerouse Jul 13, 2022
a21aac2
Work on switching to the v2 runtime.
blakerouse Jul 19, 2022
03e10d9
More work on switching to v2 runtime.
blakerouse Jul 20, 2022
08ba9cf
Merge branch 'feature-arch-v2' into v2-runtime-start
blakerouse Jul 20, 2022
f30873b
Cleanup some imports.
blakerouse Jul 20, 2022
6c1d9f6
More import cleanups.
blakerouse Jul 20, 2022
e0f4f72
Add TODO to FleetServerComponentModifier.
blakerouse Jul 20, 2022
b95cf8c
More cleanup and removals.
blakerouse Jul 21, 2022
d636633
Remove more.
blakerouse Jul 21, 2022
b32ea2a
Delete more unused code.
blakerouse Jul 21, 2022
1659555
Clean up step_download from refactor.
blakerouse Jul 21, 2022
1191d10
Remove outdated managed_mode_test.go.
blakerouse Jul 21, 2022
3c60aae
Merge branch 'v2-runtime-start' into v2-runtime-delete-more
blakerouse Jul 21, 2022
c8f9c45
Fixes from code review and lint.
blakerouse Jul 22, 2022
fc192fd
Merge branch 'v2-runtime-start' into v2-runtime-delete-more
blakerouse Jul 22, 2022
c002f85
Merge branch 'feature-arch-v2' into v2-runtime-delete-more
blakerouse Jul 26, 2022
24732cf
Fix lint and missing errcheck.
blakerouse Jul 26, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,6 @@ elastic-agent.yml.*
fleet.yml
fleet.yml.lock
fleet.yml.old
internal/pkg/agent/operation/tests/scripts/short--1.0.yml
internal/pkg/agent/operation/tests/scripts/configurable-1.0-darwin-x86/configurable
internal/pkg/agent/operation/tests/scripts/servicable-1.0-darwin-x86/configurable
internal/pkg/agent/operation/tests/scripts/configurable-1.0-darwin-x86_64/configurable
internal/pkg/agent/operation/tests/scripts/serviceable-1.0-darwin-x86_64/serviceable
internal/pkg/agent/operation/tests/scripts/configurable
internal/pkg/agent/operation/tests/scripts/serviceable
internal/pkg/agent/application/fleet.yml
internal/pkg/agent/transpiler/tests/exec-1.0-darwin-x86_64/exec
pkg/component/fake/fake
Expand Down
131 changes: 0 additions & 131 deletions dev-tools/cmd/buildspec/buildspec.go

This file was deleted.

2 changes: 2 additions & 0 deletions dev-tools/mage/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,8 @@ func CreateSHA512File(file string) error {
//nolint:gosec // permissions are correct
return os.WriteFile(file+".sha512", []byte(out), 0644)
}

// GetSHA512Hash returns SHA512 hash of file.
func GetSHA512Hash(file string) (string, error) {
f, err := os.Open(file)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions dev-tools/mage/pkgtypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// you may not use this file except in compliance with the Elastic License.

//nolint:goconst // avoiding const check for Deb/Zip

package mage

import (
Expand Down
33 changes: 2 additions & 31 deletions internal/pkg/agent/application/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,9 @@ package application
import (
"fmt"
"path/filepath"
goruntime "runtime"
"strconv"

"go.elastic.co/apm"

"github.com/elastic/go-sysinfo"

"github.com/elastic/elastic-agent/internal/pkg/agent/application/coordinator"
"github.com/elastic/elastic-agent/internal/pkg/agent/application/info"
"github.com/elastic/elastic-agent/internal/pkg/agent/application/paths"
Expand All @@ -35,18 +31,15 @@ type discoverFunc func() ([]string, error)
// ErrNoConfiguration is returned when no configuration are found.
var ErrNoConfiguration = errors.New("no configuration found", errors.TypeConfig)

// PlatformModifier can modify the platform details before the runtime specifications are loaded.
type PlatformModifier func(detail component.PlatformDetail) component.PlatformDetail

// New creates a new Agent and bootstrap the required subsystem.
func New(
log *logger.Logger,
agentInfo *info.AgentInfo,
reexec coordinator.ReExecManager,
tracer *apm.Tracer,
modifiers ...PlatformModifier,
modifiers ...component.PlatformModifier,
) (*coordinator.Coordinator, error) {
platform, err := getPlatformDetail(modifiers...)
platform, err := component.LoadPlatformDetail(modifiers...)
if err != nil {
return nil, fmt.Errorf("failed to gather system information: %w", err)
}
Expand Down Expand Up @@ -137,28 +130,6 @@ func New(
return coord, nil
}

func getPlatformDetail(modifiers ...PlatformModifier) (component.PlatformDetail, error) {
info, err := sysinfo.Host()
if err != nil {
return component.PlatformDetail{}, err
}
os := info.Info().OS
detail := component.PlatformDetail{
Platform: component.Platform{
OS: goruntime.GOOS,
Arch: goruntime.GOARCH,
GOOS: goruntime.GOOS,
},
Family: os.Family,
Major: strconv.Itoa(os.Major),
Minor: strconv.Itoa(os.Minor),
}
for _, modifier := range modifiers {
detail = modifier(detail)
}
return detail, nil
}

func mergeFleetConfig(rawConfig *config.Config) (storage.Store, *configuration.Configuration, error) {
path := paths.AgentConfigFile()
store := storage.NewEncryptedDiskStore(path)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"path/filepath"

"github.com/elastic/elastic-agent/internal/pkg/agent/errors"
"github.com/elastic/elastic-agent/internal/pkg/agent/program"
)

var packageArchMap = map[string]string{
Expand All @@ -24,20 +23,27 @@ var packageArchMap = map[string]string{
"darwin-binary-universal": "darwin-universal.tar.gz",
}

// Artifact provides info for fetching from artifact store.
type Artifact struct {
Name string
Cmd string
Artifact string
}

// GetArtifactName constructs a path to a downloaded artifact
func GetArtifactName(spec program.Spec, version, operatingSystem, arch string) (string, error) {
func GetArtifactName(a Artifact, version, operatingSystem, arch string) (string, error) {
key := fmt.Sprintf("%s-binary-%s", operatingSystem, arch)
suffix, found := packageArchMap[key]
if !found {
return "", errors.New(fmt.Sprintf("'%s' is not a valid combination for a package", key), errors.TypeConfig)
}

return fmt.Sprintf("%s-%s-%s", spec.CommandName(), version, suffix), nil
return fmt.Sprintf("%s-%s-%s", a.Cmd, version, suffix), nil
}

// GetArtifactPath returns a full path of artifact for a program in specific version
func GetArtifactPath(spec program.Spec, version, operatingSystem, arch, targetDir string) (string, error) {
artifactName, err := GetArtifactName(spec, version, operatingSystem, arch)
func GetArtifactPath(a Artifact, version, operatingSystem, arch, targetDir string) (string, error) {
artifactName, err := GetArtifactName(a, version, operatingSystem, arch)
if err != nil {
return "", err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
"github.com/hashicorp/go-multierror"
"go.elastic.co/apm"

"github.com/elastic/elastic-agent/internal/pkg/agent/program"
"github.com/elastic/elastic-agent/internal/pkg/artifact/download"
"github.com/elastic/elastic-agent/internal/pkg/agent/application/upgrade/artifact"
"github.com/elastic/elastic-agent/internal/pkg/agent/application/upgrade/artifact/download"
)

// Downloader is a downloader with a predefined set of downloaders.
Expand All @@ -34,13 +34,13 @@ func NewDownloader(downloaders ...download.Downloader) *Downloader {

// Download fetches the package from configured source.
// Returns absolute path to downloaded package and an error.
func (e *Downloader) Download(ctx context.Context, spec program.Spec, version string) (string, error) {
func (e *Downloader) Download(ctx context.Context, a artifact.Artifact, version string) (string, error) {
var err error
span, ctx := apm.StartSpan(ctx, "download", "app.internal")
defer span.End()

for _, d := range e.dd {
s, e := d.Download(ctx, spec, version)
s, e := d.Download(ctx, a, version)
if e == nil {
return s, nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ import (
"errors"
"testing"

"github.com/stretchr/testify/assert"
"github.com/elastic/elastic-agent/internal/pkg/agent/application/upgrade/artifact"
"github.com/elastic/elastic-agent/internal/pkg/agent/application/upgrade/artifact/download"

"github.com/elastic/elastic-agent/internal/pkg/agent/program"
"github.com/elastic/elastic-agent/internal/pkg/artifact/download"
"github.com/stretchr/testify/assert"
)

type FailingDownloader struct {
called bool
}

func (d *FailingDownloader) Download(ctx context.Context, _ program.Spec, _ string) (string, error) {
func (d *FailingDownloader) Download(ctx context.Context, _ artifact.Artifact, _ string) (string, error) {
d.called = true
return "", errors.New("failing")
}
Expand All @@ -30,7 +30,7 @@ type SuccDownloader struct {
called bool
}

func (d *SuccDownloader) Download(ctx context.Context, _ program.Spec, _ string) (string, error) {
func (d *SuccDownloader) Download(ctx context.Context, _ artifact.Artifact, _ string) (string, error) {
d.called = true
return "succ", nil
}
Expand Down Expand Up @@ -59,7 +59,7 @@ func TestComposed(t *testing.T) {

for _, tc := range testCases {
d := NewDownloader(tc.downloaders[0], tc.downloaders[1])
r, _ := d.Download(context.TODO(), program.Spec{Name: "a"}, "b")
r, _ := d.Download(context.TODO(), artifact.Artifact{Name: "a"}, "b")

assert.Equal(t, tc.expectedResult, r == "succ")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (

"github.com/hashicorp/go-multierror"

"github.com/elastic/elastic-agent/internal/pkg/agent/program"
"github.com/elastic/elastic-agent/internal/pkg/artifact/download"
"github.com/elastic/elastic-agent/internal/pkg/agent/application/upgrade/artifact"
"github.com/elastic/elastic-agent/internal/pkg/agent/application/upgrade/artifact/download"
)

// Verifier is a verifier with a predefined set of verifiers.
Expand All @@ -32,13 +32,13 @@ func NewVerifier(verifiers ...download.Verifier) *Verifier {
}

// Verify checks the package from configured source.
func (e *Verifier) Verify(spec program.Spec, version string) error {
func (e *Verifier) Verify(a artifact.Artifact, version string) error {
var err error
var checksumMismatchErr *download.ChecksumMismatchError
var invalidSignatureErr *download.InvalidSignatureError

for _, v := range e.vv {
e := v.Verify(spec, version)
e := v.Verify(a, version)
if e == nil {
// Success
return nil
Expand Down
Loading