Skip to content

Commit

Permalink
Set CharmModifiedVersion in annotations to trigger rolling upgrade wh…
Browse files Browse the repository at this point in the history
…en upgrade-charm was run;
  • Loading branch information
ycliuhw committed Jul 17, 2020
1 parent ca77c5b commit c572dfa
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 14 deletions.
5 changes: 3 additions & 2 deletions caas/broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,9 @@ const (

// DeploymentParams defines parameters for specifying how a service is deployed.
type DeploymentParams struct {
DeploymentType DeploymentType
ServiceType ServiceType
DeploymentType DeploymentType
ServiceType ServiceType
CharmModifiedVersion int
}

// ServiceParams defines parameters used to create a service.
Expand Down
9 changes: 8 additions & 1 deletion caas/kubernetes/provider/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ var (
annotationControllerUUIDKey = jujuAnnotationKey("controller")
annotationControllerIsControllerKey = jujuAnnotationKey("is-controller")
annotationUnit = jujuAnnotationKey("unit")
annotationCharmModifiedVersionKey = jujuAnnotationKey("charm-modified-version")
)

type kubernetesClient struct {
Expand Down Expand Up @@ -1011,7 +1012,13 @@ func (k *kubernetesClient) ensureService(
return errors.Annotatef(err, "parsing unit spec for %s", appName)
}

annotations := resourceTagsToAnnotations(params.ResourceTags)
annotations := resourceTagsToAnnotations(params.ResourceTags).
// To solve https://bugs.launchpad.net/juju/+bug/1875481/comments/23 (`jujud caas-unit-init --upgrade`
// does NOT work on containers are not using root as default USER),
// CharmModifiedVersion is added for triggering rolling upgrade on workload pods to synchronise
// charm files to workload pods via init container when charm was upgraded.
// This approach was inspired from `kubectl rollout restart`.
Add(annotationCharmModifiedVersionKey, strconv.Itoa(params.Deployment.CharmModifiedVersion))

// ensure configmap.
if len(workloadSpec.ConfigMaps) > 0 {
Expand Down
5 changes: 5 additions & 0 deletions worker/caasoperator/caasoperator.go
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,11 @@ func (op *caasOperator) remoteInit(client exec.Executor, unit names.UnitTag, run
default:
return errors.NotFoundf("container not running")
}
if params.InitType == UnitUpgrade {
op.config.Logger.Debugf("init process has been disabled for upgrade-charm for CAAS.")
// TODO(caas): remove remote-init for upgrade-charm process.
return nil
}
return errors.Trace(initializeUnit(params, cancel))
}

Expand Down
22 changes: 11 additions & 11 deletions worker/caasunitprovisioner/deployment_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,9 @@ func provisionInfoToServiceParams(info *apicaasunitprovisioner.ProvisioningInfo)
Devices: info.Devices,
OperatorImagePath: info.OperatorImagePath,
Deployment: caas.DeploymentParams{
DeploymentType: caas.DeploymentType(info.DeploymentInfo.DeploymentType),
ServiceType: caas.ServiceType(info.DeploymentInfo.ServiceType),
DeploymentType: caas.DeploymentType(info.DeploymentInfo.DeploymentType),
ServiceType: caas.ServiceType(info.DeploymentInfo.ServiceType),
CharmModifiedVersion: info.DeploymentInfo.CharmModifiedVersion,
},
}
if len(info.PodSpec) > 0 {
Expand All @@ -245,16 +246,15 @@ func provisionInfoToServiceParams(info *apicaasunitprovisioner.ProvisioningInfo)

// isProvisionInfoChanged checks if podspec or raw k8s spec changed or not.
func isProvisionInfoEqual(newInfo, oldInfo *apicaasunitprovisioner.ProvisioningInfo) bool {
var newK8sSpec, newRawK8sSpec, oldK8sSpec, oldRawK8sSpec string
if newInfo != nil {
newK8sSpec = newInfo.PodSpec
newRawK8sSpec = newInfo.RawK8sSpec
if newInfo == nil && oldInfo == nil {
return true
} else if newInfo == nil || oldInfo == nil {
return false
}
if oldInfo != nil {
oldK8sSpec = oldInfo.PodSpec
oldRawK8sSpec = oldInfo.RawK8sSpec
}
return newK8sSpec == oldK8sSpec && newRawK8sSpec == oldRawK8sSpec

return newInfo.PodSpec == oldInfo.PodSpec &&
newInfo.RawK8sSpec == oldInfo.RawK8sSpec &&
newInfo.DeploymentInfo.CharmModifiedVersion == oldInfo.DeploymentInfo.CharmModifiedVersion
}

func updateApplicationService(appTag names.ApplicationTag, svc *caas.Service, updater ApplicationUpdater) error {
Expand Down

0 comments on commit c572dfa

Please sign in to comment.