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 all 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
30 changes: 18 additions & 12 deletions dev-tools/mage/pkgtypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// or more contributor license agreements. Licensed under the Elastic License;
// 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 Expand Up @@ -40,6 +39,13 @@ const (
defaultBinaryName = "{{.Name}}-{{.Version}}{{if .Snapshot}}-SNAPSHOT{{end}}{{if .OS}}-{{.OS}}{{end}}{{if .Arch}}-{{.Arch}}{{end}}"

componentConfigMode os.FileMode = 0600

rpm = "rpm"
deb = "deb"
zipExt = "zip"
targz = "tar.gz"
docker = "docker"
invalid = "invalid"
)

var (
Expand Down Expand Up @@ -204,17 +210,17 @@ func getOSArchName(platform BuildPlatform, t PackageType) (string, error) {
func (typ PackageType) String() string {
switch typ {
case RPM:
return "rpm"
return rpm
case Deb:
return "deb"
return deb
case Zip:
return "zip"
return zipExt
case TarGz:
return "tar.gz"
return targz
case Docker:
return "docker"
return docker
default:
return "invalid"
return invalid
}
}

Expand All @@ -226,15 +232,15 @@ func (typ PackageType) MarshalText() ([]byte, error) {
// UnmarshalText returns a PackageType based on the given text.
func (typ *PackageType) UnmarshalText(text []byte) error {
switch strings.ToLower(string(text)) {
case "rpm":
case rpm:
*typ = RPM
case "deb":
case deb:
*typ = Deb
case "tar.gz", "tgz", "targz":
case targz, "tgz", "targz":
*typ = TarGz
case "zip":
case zipExt:
*typ = Zip
case "docker":
case docker:
*typ = Docker
default:
return errors.Errorf("unknown package type: %v", string(text))
Expand Down
35 changes: 3 additions & 32 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 Expand Up @@ -208,7 +179,7 @@ func externalConfigsGlob() string {
}

func discoverer(patterns ...string) discoverFunc {
var p []string
p := make([]string, 0, len(patterns))
for _, newP := range patterns {
if len(newP) == 0 {
continue
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
Loading