Skip to content

Commit

Permalink
chore: log removed model config attr on import
Browse files Browse the repository at this point in the history
  • Loading branch information
wallyworld committed Dec 18, 2024
1 parent 67ba03f commit 5ee2a69
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion caas/kubernetes/provider/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ func (k *kubernetesClient) Bootstrap(
return nil, errors.NotSupportedf("set base for bootstrapping to kubernetes")
}

// Validate workload storage is available to the controller
// Validate workload storage is available to the controller.
storageClass, err := k.validateControllerWorkloadStorage(ctx)
if err != nil {
return nil, errors.Trace(err)
Expand Down
10 changes: 8 additions & 2 deletions domain/modelconfig/modelmigration/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/juju/description/v8"
"github.com/juju/errors"

"github.com/juju/juju/core/logger"
"github.com/juju/juju/core/modelmigration"
"github.com/juju/juju/domain/modelconfig/service"
"github.com/juju/juju/domain/modelconfig/state"
Expand All @@ -23,9 +24,12 @@ type Coordinator interface {
}

// RegisterImport registers the import operations with the given coordinator.
func RegisterImport(coordinator Coordinator, defaultsProvider service.ModelDefaultsProvider) {
func RegisterImport(
coordinator Coordinator, defaultsProvider service.ModelDefaultsProvider, logger logger.Logger,
) {
coordinator.Add(&importOperation{
defaultsProvider: defaultsProvider,
logger: logger,
})
}

Expand All @@ -43,6 +47,7 @@ type ImportService interface {
type importOperation struct {
modelmigration.BaseOperation

logger logger.Logger
service ImportService
defaultsProvider service.ModelDefaultsProvider
}
Expand Down Expand Up @@ -86,8 +91,9 @@ func (i *importOperation) Execute(ctx context.Context, model description.Model)
defaultAttrs.Add(k)
}

for k := range attrs {
for k, v := range attrs {
if !defaultAttrs.Contains(k) {
i.logger.Debugf("model config attribute %s=%v is removed on import", k, v)
delete(attrs, k)
}
}
Expand Down
10 changes: 6 additions & 4 deletions domain/modelconfig/modelmigration/import_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

"github.com/juju/juju/domain/modeldefaults"
"github.com/juju/juju/environs/config"
loggertesting "github.com/juju/juju/internal/logger/testing"
)

type importSuite struct {
Expand All @@ -39,7 +40,7 @@ func (s *importSuite) TestRegisterImport(c *gc.C) {

s.coordinator.EXPECT().Add(gomock.Any())

RegisterImport(s.coordinator, s.modelDefaultsProvider)
RegisterImport(s.coordinator, s.modelDefaultsProvider, loggertesting.WrapCheckLog(c))
}

func (s *importSuite) TestEmptyModelConfig(c *gc.C) {
Expand All @@ -48,7 +49,7 @@ func (s *importSuite) TestEmptyModelConfig(c *gc.C) {
// Empty model.
model := description.NewModel(description.ModelArgs{})

op := s.newImportOperation()
op := s.newImportOperation(c)
err := op.Execute(context.Background(), model)
c.Assert(err, jc.ErrorIs, errors.NotValid)
}
Expand Down Expand Up @@ -79,14 +80,15 @@ func (s *importSuite) TestModelConfig(c *gc.C) {
Config: config.AllAttrs(),
})

op := s.newImportOperation()
op := s.newImportOperation(c)
err = op.Execute(context.Background(), model)
c.Assert(err, jc.ErrorIsNil)
}

func (s *importSuite) newImportOperation() *importOperation {
func (s *importSuite) newImportOperation(c *gc.C) *importOperation {
return &importOperation{
service: s.service,
defaultsProvider: s.modelDefaultsProvider,
logger: loggertesting.WrapCheckLog(c),
}
}
2 changes: 1 addition & 1 deletion domain/modelmigration/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func ImportOperations(
credential.RegisterImport(coordinator, logger.Child("credential"))
model.RegisterImport(coordinator, logger.Child("model"))
keymanager.RegisterImport(coordinator, logger.Child("keymanager"))
modelconfig.RegisterImport(coordinator, modelDefaultsProvider)
modelconfig.RegisterImport(coordinator, modelDefaultsProvider, logger.Child("modelconfig"))
access.RegisterImport(coordinator, logger.Child("access"))
network.RegisterImport(coordinator, logger.Child("network"))
machine.RegisterImport(coordinator, logger.Child("machine"))
Expand Down

0 comments on commit 5ee2a69

Please sign in to comment.