diff --git a/cmd/opampsupervisor/supervisor/config/config_test.go b/cmd/opampsupervisor/supervisor/config/config_test.go index c0f87b38e185..aea7f713b08d 100644 --- a/cmd/opampsupervisor/supervisor/config/config_test.go +++ b/cmd/opampsupervisor/supervisor/config/config_test.go @@ -540,6 +540,7 @@ agent: OrphanDetectionInterval: DefaultSupervisor().Agent.OrphanDetectionInterval, ConfigApplyTimeout: DefaultSupervisor().Agent.ConfigApplyTimeout, BootstrapTimeout: DefaultSupervisor().Agent.BootstrapTimeout, + Signature: DefaultSupervisor().Agent.Signature, }, Telemetry: DefaultSupervisor().Telemetry, } @@ -625,6 +626,7 @@ telemetry: HealthCheckPort: 8089, OpAMPServerPort: 8090, PassthroughLogs: true, + Signature: DefaultSupervisor().Agent.Signature, }, Telemetry: Telemetry{ Logs: Logs{ @@ -659,6 +661,7 @@ agent: OrphanDetectionInterval: DefaultSupervisor().Agent.OrphanDetectionInterval, ConfigApplyTimeout: DefaultSupervisor().Agent.ConfigApplyTimeout, BootstrapTimeout: DefaultSupervisor().Agent.BootstrapTimeout, + Signature: DefaultSupervisor().Agent.Signature, }, Telemetry: DefaultSupervisor().Telemetry, } diff --git a/cmd/opampsupervisor/supervisor/package_test.go b/cmd/opampsupervisor/supervisor/package_test.go index e97abe0d065d..d87e6ce0c0b2 100644 --- a/cmd/opampsupervisor/supervisor/package_test.go +++ b/cmd/opampsupervisor/supervisor/package_test.go @@ -10,7 +10,6 @@ import ( ) func TestMain(m *testing.M) { - goleak.VerifyTestMain( m, // This leaky goroutine seems to come from the cosign dependency tree. diff --git a/cmd/opampsupervisor/supervisor/packages.go b/cmd/opampsupervisor/supervisor/packages.go index 3d779b3e97d7..a163181e8b4e 100644 --- a/cmd/opampsupervisor/supervisor/packages.go +++ b/cmd/opampsupervisor/supervisor/packages.go @@ -201,7 +201,7 @@ func (p *packageManager) UpdateContent(ctx context.Context, packageName string, // Create a backup in case we fail to write the agent // verify collector backup path is clear agentBackupPath := filepath.Join(p.storageDir, "collector.bak") - if err := renameFile(p.agentExePath, agentBackupPath); err != nil { + if err = renameFile(p.agentExePath, agentBackupPath); err != nil { return fmt.Errorf("rename collector exe path to backup path: %w", err) } @@ -226,7 +226,7 @@ func (p *packageManager) UpdateContent(ctx context.Context, packageName string, } // open collector destination file - agentFile, err := os.OpenFile(p.agentExePath, os.O_RDWR, 0700) + agentFile, err := os.OpenFile(p.agentExePath, os.O_RDWR|os.O_CREATE, 0o700) if err != nil { return fmt.Errorf("open file: %w", err) } @@ -294,7 +294,7 @@ func (p packageManager) SetLastReportedStatuses(statuses *protobufs.PackageStatu return fmt.Errorf("marshal statuses: %w", err) } - err = os.WriteFile(p.lastPackageStatusPath(), lastStatusBytes, 0600) + err = os.WriteFile(p.lastPackageStatusPath(), lastStatusBytes, 0o600) if err != nil { return fmt.Errorf("write package statues: %w", err) } @@ -399,7 +399,7 @@ func renameFile(srcPath, dstPath string) error { // verify dstPath is cleared up if _, err := os.Stat(dstPath); err == nil { // delete existing file at dstPath - if err := os.Remove(dstPath); err != nil { + if err = os.Remove(dstPath); err != nil { return fmt.Errorf("remove existing file at destination path: %w", err) } } else if !os.IsNotExist(err) { diff --git a/cmd/opampsupervisor/supervisor/packages_test.go b/cmd/opampsupervisor/supervisor/packages_test.go index 1dbec0f092d6..7a420a45bea7 100644 --- a/cmd/opampsupervisor/supervisor/packages_test.go +++ b/cmd/opampsupervisor/supervisor/packages_test.go @@ -38,8 +38,8 @@ func TestNewPackageManager(t *testing.T) { storageDir := filepath.Join(tmpDir, "storage") defaultSigOpts := config.DefaultSupervisor().Agent.Signature - require.NoError(t, os.MkdirAll(storageDir, 0700)) - require.NoError(t, os.WriteFile(agentFile, []byte(testAgentFileContents), 0600)) + require.NoError(t, os.MkdirAll(storageDir, 0o700)) + require.NoError(t, os.WriteFile(agentFile, []byte(testAgentFileContents), 0o600)) pm, err := newPackageManager(agentFile, storageDir, "v0.110.0", &persistentState{}, defaultSigOpts, nil) require.NoError(t, err) @@ -54,7 +54,7 @@ func TestNewPackageManager(t *testing.T) { storageDir := filepath.Join(tmpDir, "storage") defaultSigOpts := config.DefaultSupervisor().Agent.Signature - require.NoError(t, os.MkdirAll(storageDir, 0700)) + require.NoError(t, os.MkdirAll(storageDir, 0o700)) _, err := newPackageManager(agentFile, storageDir, "v0.110.0", &persistentState{}, defaultSigOpts, nil) require.ErrorContains(t, err, "open agent:") @@ -81,7 +81,6 @@ func TestPackageManager_AllPackagesHash(t *testing.T) { by, err = pm2.AllPackagesHash() require.NoError(t, err) require.Equal(t, allPackagesHash, by) - } func TestPackageManager_Packages(t *testing.T) { @@ -281,8 +280,8 @@ func initPackageManager(t *testing.T, tmpDir string) *packageManager { storageDir := filepath.Join(tmpDir, "storage") defaultSigOpts := config.DefaultSupervisor().Agent.Signature - require.NoError(t, os.MkdirAll(storageDir, 0700)) - require.NoError(t, os.WriteFile(agentFile, []byte(testAgentFileContents), 0600)) + require.NoError(t, os.MkdirAll(storageDir, 0o700)) + require.NoError(t, os.WriteFile(agentFile, []byte(testAgentFileContents), 0o600)) ps, err := loadOrCreatePersistentState(filepath.Join(tmpDir, "persistent_state.yaml")) require.NoError(t, err) diff --git a/cmd/opampsupervisor/supervisor/persistence.go b/cmd/opampsupervisor/supervisor/persistence.go index 30e922fdaac7..481778d82c1d 100644 --- a/cmd/opampsupervisor/supervisor/persistence.go +++ b/cmd/opampsupervisor/supervisor/persistence.go @@ -93,8 +93,10 @@ func createNewPersistentState(file string) (*persistentState, error) { // to/from a hex string. type hexEncodedBytes []byte -var _ yaml.Marshaler = (*hexEncodedBytes)(nil) -var _ yaml.Unmarshaler = (*hexEncodedBytes)(nil) +var ( + _ yaml.Marshaler = (*hexEncodedBytes)(nil) + _ yaml.Unmarshaler = (*hexEncodedBytes)(nil) +) func (h hexEncodedBytes) MarshalYAML() (any, error) { return hex.EncodeToString(h), nil