Skip to content

Commit

Permalink
feat: renaming of func (#539)
Browse files Browse the repository at this point in the history
Signed-off-by: Smuu <[email protected]>
  • Loading branch information
smuu authored Aug 8, 2024
1 parent bce2f54 commit edceaec
Show file tree
Hide file tree
Showing 19 changed files with 29 additions and 29 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ Simple example:
if err != nil {
t.Fatalf("Error setting image: %v", err)
}
err = instance.SetCommand("sleep", "infinity")
err = instance.SetStartCommand("sleep", "infinity")
if err != nil {
t.Fatalf("Error setting command: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion e2e/basic/basic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func (ts *TestSuite) TestBasic() {
ts.Require().NoError(err)

ts.Require().NoError(target.Build().SetImage(ctx, testImage))
ts.Require().NoError(target.Build().SetCommand("sleep", "infinity"))
ts.Require().NoError(target.Build().SetStartCommand("sleep", "infinity"))
ts.Require().NoError(target.Build().Commit())

ts.T().Cleanup(func() {
Expand Down
2 changes: 1 addition & 1 deletion e2e/basic/observability_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ scrape_configs:
err = target.SetImage(targetImage)
require.NoError(t, err, "Error setting target image")

err = target.SetCommand("sh", "-c", "while true; do curl -X POST http://localhost:8888/v1/traces; sleep 5; done")
err = target.SetStartCommand("sh", "-c", "while true; do curl -X POST http://localhost:8888/v1/traces; sleep 5; done")
require.NoError(t, err, "Error setting target command")

require.NoError(t, target.AddSidecar(context.Background(), observabilitySidecar))
Expand Down
2 changes: 1 addition & 1 deletion e2e/basic/rbac_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func TestRBAC(t *testing.T) {
if err != nil {
t.Fatalf("Error setting image: %v", err)
}
err = instance.SetCommand("sleep", "infinity")
err = instance.SetStartCommand("sleep", "infinity")
if err != nil {
t.Fatalf("Error setting command: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion e2e/basic/reverse_proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func TestReverseProxy(t *testing.T) {
err = main.SetImage("alpine:latest")
require.NoError(t, err, "Error setting image")

err = main.SetCommand("sleep", "infinite")
err = main.SetStartCommand("sleep", "infinite")
require.NoError(t, err, "Error executing command")

require.NoError(t, main.Commit(), "Error committing instance")
Expand Down
2 changes: 1 addition & 1 deletion e2e/netshaper/netshaper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (s *Suite) TestNetShaperBandwidth() {
s.Require().NoError(err)

s.Require().NoError(iperfMother.Build().SetImage(ctx, iperfImage))
s.Require().NoError(iperfMother.Build().SetCommand("iperf3", "-s"))
s.Require().NoError(iperfMother.Build().SetStartCommand("iperf3", "-s"))
s.Require().NoError(iperfMother.Network().AddPortTCP(iperfPort))
s.Require().NoError(iperfMother.Build().Commit())

Expand Down
2 changes: 1 addition & 1 deletion e2e/system/build_from_git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (s *Suite) TestBuildFromGitWithModifications() {
})
s.Require().NoError(err)

s.Require().NoError(target.Build().SetCommand("sleep", "infinity"))
s.Require().NoError(target.Build().SetStartCommand("sleep", "infinity"))

err = target.Storage().AddFileBytes([]byte("Hello, world!"), "/home/hello.txt", "root:root")
s.Require().NoError(err, "Error adding file")
Expand Down
2 changes: 1 addition & 1 deletion e2e/system/start_callback_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func TestStartWithCallback(t *testing.T) {
})
require.NoError(t, err, "Error setting readiness probe")

err = target.Build().SetCommand([]string{"sleep", sleepTimeBeforeReady, "&&", nginxCommand}...)
err = target.Build().SetStartCommand([]string{"sleep", sleepTimeBeforeReady, "&&", nginxCommand}...)
require.NoError(t, err, "Error setting command")

t.Cleanup(func() {
Expand Down
2 changes: 1 addition & 1 deletion e2e/tshark/tshark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func TestTshark(t *testing.T) {
require.NoError(t, err, "error creating instance")

require.NoError(t, target.Build().SetImage(ctx, "busybox"))
require.NoError(t, target.Build().SetCommand("sleep", "infinity"))
require.NoError(t, target.Build().SetStartCommand("sleep", "infinity"))

t.Log("getting minio configs")
minioConf, err := kn.MinioClient.GetConfigs(ctx)
Expand Down
4 changes: 2 additions & 2 deletions pkg/instance/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ func (b *build) SetGitRepo(ctx context.Context, gitContext builder.GitContext) e
return b.builderFactory.BuildImageFromGitRepo(ctx, gitContext, imageName)
}

// SetCommand sets the command to run in the instance
// SetStartCommand sets the command to run in the instance
// This function can only be called when the instance is in state 'Preparing' or 'Committed'
func (b *build) SetCommand(command ...string) error {
func (b *build) SetStartCommand(command ...string) error {
if !b.instance.IsInState(StatePreparing, StateCommitted) {
return ErrSettingCommand.WithParams(b.instance.state.String())
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/instance/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ var (
ErrCannotCreateInstance = errors.New("Cannot Create Instance", "cannot create instance")
ErrCannotSetImage = errors.New("Cannot Set Image", "cannot set image")
ErrCannotCommitInstance = errors.New("Cannot Commit Instance", "cannot commit instance")
ErrCannotSetCommand = errors.New("Cannot Set Command", "cannot set command")
ErrCannotSetStartCommand = errors.New("Cannot Set Start Command", "cannot set start command")
ErrCannotAddPolicyRule = errors.New("Cannot Add Policy Rule", "cannot add policy rule")
ErrCannotStartInstance = errors.New("Cannot Start Instance", "cannot start instance")
ErrMinioNotInitialized = errors.New("MinioNotInitialized", "minio not initialized")
Expand Down
2 changes: 1 addition & 1 deletion pkg/instance/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ func (n *network) Enable(ctx context.Context) error {
return nil
}

// NetworkIsDisabled returns true if the network of the instance is disabled
// IsDisabled returns true if the network of the instance is disabled
// This function can only be called in the state 'Started'
func (n *network) IsDisabled(ctx context.Context) (bool, error) {
if !n.instance.IsInState(StateStarted) {
Expand Down
8 changes: 4 additions & 4 deletions pkg/instance/security.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ func (s *security) SetPrivileged(privileged bool) error {
return nil
}

// AddCapability adds a capability to the instance
// AddKubernetesCapability adds a Kubernetes capability to the instance
// This function can only be called in the state 'Preparing' or 'Committed'
func (s *security) AddCapability(capability string) error {
func (s *security) AddKubernetesCapability(capability string) error {
if !s.instance.IsInState(StatePreparing, StateCommitted) {
return ErrAddingCapabilityNotAllowed.WithParams(s.instance.state.String())
}
Expand All @@ -55,9 +55,9 @@ func (s *security) AddCapability(capability string) error {
return nil
}

// AddCapabilities adds multiple capabilities to the instance
// AddKubernetesCapabilities adds multiple Kubernetes capabilities to the instance
// This function can only be called in the state 'Preparing' or 'Committed'
func (s *security) AddCapabilities(capabilities []string) error {
func (s *security) AddKubernetesCapabilities(capabilities []string) error {
if !s.instance.IsInState(StatePreparing, StateCommitted) {
return ErrAddingCapabilitiesNotAllowed.WithParams(s.instance.state.String())
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/knuu/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ var (
ErrCannotCreateInstance = errors.New("CannotCreateInstance", "cannot create instance")
ErrCannotSetImage = errors.New("CannotSetImage", "cannot set image")
ErrCannotCommitInstance = errors.New("CannotCommitInstance", "cannot commit instance")
ErrCannotSetCommand = errors.New("CannotSetCommand", "cannot set command")
ErrCannotSetStartCommand = errors.New("CannotSetStartCommand", "cannot set start command")
ErrCannotAddPolicyRule = errors.New("CannotAddPolicyRule", "cannot add policy rule")
ErrCannotStartInstance = errors.New("CannotStartInstance", "cannot start instance")
ErrMinioNotInitialized = errors.New("MinioNotInitialized", "minio not initialized")
Expand Down
12 changes: 6 additions & 6 deletions pkg/knuu/instance_old.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ func (i *Instance) SetImageInstant(image string) error {
}

// Deprecated: Use the new package knuu instead.
func (i *Instance) SetCommand(command ...string) error {
return i.Instance.Build().SetCommand(command...)
func (i *Instance) SetStartCommand(command ...string) error {
return i.Instance.Build().SetStartCommand(command...)
}

// Deprecated: Use the new package knuu instead.
Expand Down Expand Up @@ -212,13 +212,13 @@ func (i *Instance) SetPrivileged(privileged bool) error {
}

// Deprecated: Use the new package knuu instead.
func (i *Instance) AddCapability(capability string) error {
return i.Instance.Security().AddCapability(capability)
func (i *Instance) AddKubernetesCapability(capability string) error {
return i.Instance.Security().AddKubernetesCapability(capability)
}

// Deprecated: Use the new package knuu instead.
func (i *Instance) AddCapabilities(capabilities []string) error {
return i.Instance.Security().AddCapabilities(capabilities)
func (i *Instance) AddKubernetesCapabilities(capabilities []string) error {
return i.Instance.Security().AddKubernetesCapabilities(capabilities)
}

// Deprecated: Use the new package knuu instead.
Expand Down
4 changes: 2 additions & 2 deletions pkg/knuu/knuu.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,9 @@ func (k *Knuu) handleTimeout(ctx context.Context) error {
finalCmd := strings.Join(commands, " && ")

// Run the command
if err := inst.Build().SetCommand("sh", "-c", finalCmd); err != nil {
if err := inst.Build().SetStartCommand("sh", "-c", finalCmd); err != nil {
k.Logger.Debugf("The full command generated is [%s]", finalCmd)
return ErrCannotSetCommand.Wrap(err)
return ErrCannotSetStartCommand.Wrap(err)
}

rule := rbacv1.PolicyRule{
Expand Down
2 changes: 1 addition & 1 deletion pkg/sidecars/netshaper/netshaper.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (bt *NetShaper) Initialize(ctx context.Context, sysDeps system.SystemDepend
return ErrSettingBitTwisterPrivileged.Wrap(err)
}

if err := bt.instance.Security().AddCapability(capabilityNetAdmin); err != nil {
if err := bt.instance.Security().AddKubernetesCapability(capabilityNetAdmin); err != nil {
return ErrAddingBitTwisterCapability.Wrap(err)
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/sidecars/observability/obsy.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func (o *Obsy) Initialize(ctx context.Context, sysDeps system.SystemDependencies
return ErrAddingOtelAgentConfigFile.Wrap(err)
}

if err := o.instance.Build().SetCommand(otelCollectorCommand, otelCollectorConfigArg); err != nil {
if err := o.instance.Build().SetStartCommand(otelCollectorCommand, otelCollectorConfigArg); err != nil {
return ErrSettingOtelAgentCommand.Wrap(err)
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/sidecars/tshark/tshark.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func (t *Tshark) Initialize(ctx context.Context, sysDeps system.SystemDependenci
return ErrSettingTsharkCollectorEnv.Wrap(err)
}
}
if err := t.instance.Security().AddCapability(netAdminCapability); err != nil {
if err := t.instance.Security().AddKubernetesCapability(netAdminCapability); err != nil {
return ErrAddingTsharkCollectorCapability.Wrap(err)
}
return nil
Expand Down

0 comments on commit edceaec

Please sign in to comment.