Skip to content

Commit

Permalink
feat: bugfixes
Browse files Browse the repository at this point in the history
Signed-off-by: Smuu <[email protected]>
  • Loading branch information
smuu committed Nov 10, 2023
1 parent a0dc285 commit fc809b7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
3 changes: 2 additions & 1 deletion pkg/knuu/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -973,9 +973,10 @@ func (i *Instance) Destroy() error {
}

if err := applyFunctionToInstances(i.sidecars, func(sidecar Instance) error {
logrus.Debugf("Destroying sidecar resources from '%s'", sidecar.k8sName)
return sidecar.destroyResources()
}); err != nil {
return err
return fmt.Errorf("error destroying resources for sidecars of instance '%s': %w", i.k8sName, err)
}

i.state = Destroyed
Expand Down
28 changes: 18 additions & 10 deletions pkg/knuu/instance_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,15 +294,20 @@ func (i *Instance) destroyResources() error {
return fmt.Errorf("error destroying service for instance '%s': %w", i.k8sName, err)
}

// enable network when network is disabled
disableNetwork, err := i.NetworkIsDisabled()
if err != nil {
return fmt.Errorf("error checking network status for instance '%s': %w", i.k8sName, err)
}
if disableNetwork {
err := i.EnableNetwork()
// disable network only for non-sidecar instances
if !i.isSidecar {
// enable network when network is disabled
disableNetwork, err := i.NetworkIsDisabled()
if err != nil {
return fmt.Errorf("error enabling network for instance '%s': %w", i.k8sName, err)
logrus.Debugf("error checking network status for instance")
return fmt.Errorf("error checking network status for instance '%s': %w", i.k8sName, err)
}
if disableNetwork {
err := i.EnableNetwork()
if err != nil {
logrus.Debugf("error enabling network for instance")
return fmt.Errorf("error enabling network for instance '%s': %w", i.k8sName, err)
}
}
}

Expand Down Expand Up @@ -486,18 +491,21 @@ func (i *Instance) setImageWithGracePeriod(imageName string, gracePeriod *int64)
func applyFunctionToInstances(instances []*Instance, function func(sidecar Instance) error) error {
for _, i := range instances {
if err := function(*i); err != nil {
return fmt.Errorf("error")
return fmt.Errorf("error applying function to instance '%s': %w", i.k8sName, err)
}
}
return nil
}

func setStateForSidecars(sidecars []*Instance, state InstanceState) {
// We don't handle errors here, as the function can't return an error
applyFunctionToInstances(sidecars, func(sidecar Instance) error {
err := applyFunctionToInstances(sidecars, func(sidecar Instance) error {
sidecar.state = state
return nil
})
if err != nil {
return
}
}

// isObservabilityEnabled returns true if observability is enabled
Expand Down

0 comments on commit fc809b7

Please sign in to comment.