Skip to content

Commit

Permalink
Make upgrade-controller command to support to fetch jujud image versi…
Browse files Browse the repository at this point in the history
…ons from a private registry;
  • Loading branch information
ycliuhw committed Aug 18, 2021
1 parent 8c96d7a commit 114c96c
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 50 deletions.
2 changes: 1 addition & 1 deletion api/caasapplicationprovisioner/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ type ProvisioningInfo struct {
Filesystems []storage.KubernetesFilesystemParams
Devices []devices.KubernetesDeviceParams
Series string
ImageRepo *docker.ImageRepoDetails
ImageRepo docker.ImageRepoDetails
CharmModifiedVersion int
CharmURL *charm.URL
}
Expand Down
4 changes: 1 addition & 3 deletions apiserver/facades/controller/caasmodeloperator/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,7 @@ func (a *API) ModelOperatorProvisioningInfo() (params.ModelOperatorInfo, error)
}

imageDetails := resources.DockerImageDetails{}
if imageRepo := controllerConf.CAASImageRepo(); imageRepo != nil {
imageDetails.ImageRepoDetails = *imageRepo
}
imageDetails.ImageRepoDetails = controllerConf.CAASImageRepo()
if imageDetails.RegistryPath, err = podcfg.GetJujuOCIImagePath(controllerConf,
vers.ToPatch(), version.OfficialBuild); err != nil {
return result, errors.Trace(err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,8 @@ func (a *API) OperatorProvisioningInfo(args params.Entities) (params.OperatorPro
)

imageDetails := resources.DockerImageDetails{}
if imageRepo := cfg.CAASImageRepo(); imageRepo != nil {
imageDetails.ImageRepoDetails = *imageRepo
}
imageDetails.ImageRepoDetails = cfg.CAASImageRepo()

if imageDetails.RegistryPath, err = podcfg.GetJujuOCIImagePath(
cfg, vers.ToPatch(), version.OfficialBuild,
); err != nil {
Expand Down
36 changes: 18 additions & 18 deletions apiserver/facades/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -6884,6 +6884,9 @@
"BasicAuthConfig": {
"type": "object",
"properties": {
"auth": {
"type": "string"
},
"password": {
"type": "string"
},
Expand Down Expand Up @@ -7910,6 +7913,9 @@
},
"repository": {
"type": "string"
},
"serveraddress": {
"type": "string"
}
},
"additionalProperties": false,
Expand Down Expand Up @@ -8304,9 +8310,6 @@
"TokenAuthConfig": {
"type": "object",
"properties": {
"auth": {
"type": "string"
},
"email": {
"type": "string"
},
Expand All @@ -8315,9 +8318,6 @@
},
"registrytoken": {
"type": "string"
},
"serveraddress": {
"type": "string"
}
},
"additionalProperties": false
Expand Down Expand Up @@ -9916,6 +9916,9 @@
"BasicAuthConfig": {
"type": "object",
"properties": {
"auth": {
"type": "string"
},
"password": {
"type": "string"
},
Expand Down Expand Up @@ -10075,6 +10078,9 @@
},
"repository": {
"type": "string"
},
"serveraddress": {
"type": "string"
}
},
"additionalProperties": false,
Expand Down Expand Up @@ -10182,9 +10188,6 @@
"TokenAuthConfig": {
"type": "object",
"properties": {
"auth": {
"type": "string"
},
"email": {
"type": "string"
},
Expand All @@ -10193,9 +10196,6 @@
},
"registrytoken": {
"type": "string"
},
"serveraddress": {
"type": "string"
}
},
"additionalProperties": false
Expand Down Expand Up @@ -11129,6 +11129,9 @@
"BasicAuthConfig": {
"type": "object",
"properties": {
"auth": {
"type": "string"
},
"password": {
"type": "string"
},
Expand Down Expand Up @@ -11315,6 +11318,9 @@
},
"repository": {
"type": "string"
},
"serveraddress": {
"type": "string"
}
},
"additionalProperties": false,
Expand Down Expand Up @@ -11598,9 +11604,6 @@
"TokenAuthConfig": {
"type": "object",
"properties": {
"auth": {
"type": "string"
},
"email": {
"type": "string"
},
Expand All @@ -11609,9 +11612,6 @@
},
"registrytoken": {
"type": "string"
},
"serveraddress": {
"type": "string"
}
},
"additionalProperties": false
Expand Down
2 changes: 1 addition & 1 deletion apiserver/params/caas.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ type CAASApplicationProvisioningInfo struct {
Volumes []KubernetesVolumeParams `json:"volumes,omitempty"`
Devices []KubernetesDeviceParams `json:"devices,omitempty"`
Series string `json:"series,omitempty"`
ImageRepo *docker.ImageRepoDetails `json:"image-repo,omitempty"`
ImageRepo docker.ImageRepoDetails `json:"image-repo,omitempty"`
CharmModifiedVersion int `json:"charm-modified-version,omitempty"`
CharmURL string `json:"charm-url,omitempty"`
Error *Error `json:"error,omitempty"`
Expand Down
3 changes: 1 addition & 2 deletions cloudconfig/podcfg/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ func (cfg *ControllerPodConfig) GetControllerImagePath() (string, error) {

// GetJujuDbOCIImagePath returns the juju-db oci image path.
func (cfg *ControllerPodConfig) GetJujuDbOCIImagePath() (string, error) {
imageRepoDetails := cfg.Controller.Config.CAASImageRepo()
imageRepo := imageRepoDetails.Repository
imageRepo := cfg.Controller.Config.CAASImageRepo().Repository
if imageRepo == "" {
imageRepo = JujudOCINamespace
}
Expand Down
25 changes: 20 additions & 5 deletions cmd/juju/commands/upgradecontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/juju/juju/core/model"
"github.com/juju/juju/core/permission"
"github.com/juju/juju/docker"
"github.com/juju/juju/docker/registry"
"github.com/juju/juju/environs"
"github.com/juju/juju/environs/bootstrap"
"github.com/juju/juju/environs/config"
Expand Down Expand Up @@ -268,6 +269,24 @@ func (c *upgradeControllerCommand) upgradeCAASController(ctx *cmd.Context) error
return c.notifyControllerUpgrade(ctx, client, context)
}

func listOperatorImages(controllerCfg controller.Config) (tools.Versions, error) {
imagePath, err := podcfg.GetJujuOCIImagePath(controllerCfg, version.Zero, 0)
if err != nil {
return nil, errors.Trace(err)
}

imageRepoDetails := controllerCfg.CAASImageRepo()
if !imageRepoDetails.IsPrivate() {
return docker.ListOperatorImages(imagePath)
}
reg, err := registry.NewRegistry(imageRepoDetails)
if err != nil {
return nil, errors.Trace(err)
}
defer func() { _ = reg.Close() }()
return reg.Tags(podcfg.JujudOCIName)
}

// initCAASVersions collects state relevant to an upgrade decision. The returned
// agent and client versions, and the list of currently available operator images, will
// always be accurate; the chosen version, and the flag indicating development
Expand All @@ -276,14 +295,10 @@ func (c *baseUpgradeCommand) initCAASVersions(
controllerCfg controller.Config, majorVersion int, streamsAgents tools.List,
) (tools.Versions, error) {
logger.Debugf("searching for agent images with major: %d", majorVersion)
imagePath, err := podcfg.GetJujuOCIImagePath(controllerCfg, version.Zero, 0)
availableTags, err := listOperatorImages(controllerCfg)
if err != nil {
return nil, errors.Trace(err)
}
availableTags, err := docker.ListOperatorImages(imagePath)
if err != nil {
return nil, err
}
streamsVersions := set.NewStrings()
for _, a := range streamsAgents {
streamsVersions.Add(a.Version.Number.String())
Expand Down
14 changes: 8 additions & 6 deletions controller/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -833,18 +833,20 @@ func (c Config) JujuManagementSpace() string {

// CAASOperatorImagePath sets the url of the docker image
// used for the application operator.
func (c Config) CAASOperatorImagePath() *docker.ImageRepoDetails {
o, _ := docker.NewImageRepoDetails(c.asString(CAASOperatorImagePath))
func (c Config) CAASOperatorImagePath() (o docker.ImageRepoDetails) {
if repoDetails, _ := docker.NewImageRepoDetails(c.asString(CAASOperatorImagePath)); repoDetails != nil {
return *repoDetails
}
return o
// return c.asString(CAASOperatorImagePath)
}

// CAASImageRepo sets the url of the docker repo
// used for the jujud operator and mongo images.
func (c Config) CAASImageRepo() *docker.ImageRepoDetails {
o, _ := docker.NewImageRepoDetails(c.asString(CAASImageRepo))
func (c Config) CAASImageRepo() (o docker.ImageRepoDetails) {
if repoDetails, _ := docker.NewImageRepoDetails(c.asString(CAASImageRepo)); repoDetails != nil {
return *repoDetails
}
return o
// return c.asString(CAASImageRepo)
}

// MeteringURL returns the URL to use for metering api calls.
Expand Down
2 changes: 1 addition & 1 deletion worker/caasapplicationprovisioner/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ func (a *appWorker) alive(app caas.Application) error {
Constraints: provisionInfo.Constraints,
Filesystems: provisionInfo.Filesystems,
Devices: provisionInfo.Devices,
CharmBaseImagePath: charmBaseImage,
CharmBaseImagePath: charmBaseImage,
Containers: containers,
CharmModifiedVersion: provisionInfo.CharmModifiedVersion,
}
Expand Down
17 changes: 7 additions & 10 deletions worker/caasmodelconfigmanager/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/juju/worker/v2/catacomb"

"github.com/juju/juju/api/base"
caasmodelconfigmanagerapi "github.com/juju/juju/api/caasmodelconfigmanager"
api "github.com/juju/juju/api/caasmodelconfigmanager"
"github.com/juju/juju/controller"
"github.com/juju/juju/core/watcher"
"github.com/juju/juju/docker"
Expand Down Expand Up @@ -74,8 +74,9 @@ type manager struct {
imageRepoInfo docker.ImageRepoDetails
}

// NewFacade returns a facade for caasapplicationprovisioner worker to use.
func NewFacade(caller base.APICaller) Facade {
return caasmodelconfigmanagerapi.NewClient(caller)
return api.NewClient(caller)
}

// NewWorker returns a worker that unlocks the model upgrade gate.
Expand Down Expand Up @@ -122,7 +123,7 @@ func (w *manager) loop() error {
case <-w.catacomb.Dying():
return w.catacomb.ErrDying()
case _, ok := <-controllerConfigWatcher.Changes():
w.logger.Errorf("got controller config changes")
w.logger.Debugf("got controller config changes")
if !ok {
return fmt.Errorf("controller config watcher %q closed channel", w.name)
}
Expand All @@ -131,15 +132,11 @@ func (w *manager) loop() error {
return errors.Trace(err)
}
newImageRepoInfo := controllerConfig.CAASImageRepo()
w.logger.Errorf("newImageRepoInfo -> %#v", newImageRepoInfo)
if newImageRepoInfo != nil {
w.logger.Errorf("!w.imageRepoInfo.AuthEqual(*newImageRepoInfo) -> %v", !w.imageRepoInfo.AuthEqual(*newImageRepoInfo))
}
if newImageRepoInfo != nil && !w.imageRepoInfo.AuthEqual(*newImageRepoInfo) {
if err := w.config.Broker.EnsureImageRepoSecret(*newImageRepoInfo); err != nil {
if !w.imageRepoInfo.AuthEqual(newImageRepoInfo) {
if err := w.config.Broker.EnsureImageRepoSecret(newImageRepoInfo); err != nil {
return errors.Trace(err)
}
w.imageRepoInfo = *newImageRepoInfo
w.imageRepoInfo = newImageRepoInfo
}
}
}
Expand Down

0 comments on commit 114c96c

Please sign in to comment.