Skip to content

Commit

Permalink
Merge pull request #4254 from LiilyZhang/zhangl/Issue4253
Browse files Browse the repository at this point in the history
Issue #4253 - Bug: Cert version info lost after config au…
  • Loading branch information
LiilyZhang authored Feb 27, 2025
2 parents e3be197 + 58f38fb commit dc79f63
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 6 deletions.
2 changes: 1 addition & 1 deletion clusterupgrade/cluster_upgrade_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func (w *ClusterUpgradeWorker) syncOnInit(db *bolt.DB, kubeClient *KubeClient, b
glog.Infof(cuwlog(fmt.Sprintf("Handling status %v during initialization", name)))
workDir := path.Join(baseWorkingDir, name)
if statusInStatusFile, err := checkDeploymentStatus(kubeClient, baseWorkingDir, name); err != nil {
errMessage := fmt.Sprintf("Failed to check deployment status duriing syncOnInit for nmp: %v, error: %v", name, err)
errMessage := fmt.Sprintf("Failed to check deployment status during syncOnInit for nmp: %v, error: %v", name, err)
if err = setErrorMessageInStatusFile(workDir, exchangecommon.STATUS_FAILED_JOB, errMessage); err != nil {
glog.Errorf(fmt.Sprintf("Failed to set error message (%v) for nmp: %v in the status file, error: %v", errMessage, name, err))
}
Expand Down
12 changes: 12 additions & 0 deletions common/node_management.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ func SetNodeManagementPolicyStatus(db *bolt.DB, pDevice *persistence.ExchangeDev
if dbStatus.AgentUpgradeInternal != nil {
dbStatus.AgentUpgradeInternal.DownloadAttempts = 0
}

if dbStatus.AgentUpgrade != nil {
dbStatus.AgentUpgrade.ActualStartTime = ""
dbStatus.AgentUpgrade.CompletionTime = ""
}
}

// Update the NMP status in the local db
Expand Down Expand Up @@ -95,12 +100,19 @@ func SetNodeManagementPolicyStatus(db *bolt.DB, pDevice *persistence.ExchangeDev
if newCertVer != cert_version {
updateExch = true
}
} else {
// newCertVer somehow is empty, use the cert version in the exchange
newCertVer = cert_version
}

if newConfigVer != "" {
pDevice.SetConfigVersion(db, pDevice.Id, newConfigVer)
if newConfigVer != config_version {
updateExch = true
}
} else {
// newConfigVer somehow is empty, use the config version in the exchange
newConfigVer = config_version
}

// Update the agent software version
Expand Down
12 changes: 11 additions & 1 deletion download/download_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,9 @@ func (w *DownloadWorker) DownloadAgentUpgradePackages(org string, filePath strin
swType, configType, certType := getUpgradeCSSType(upgradeVersions)
glog.V(3).Infof(dwlog(fmt.Sprintf("Upgrade versions: swType: %v, configType: %v, certType: %v", swType, configType, certType)))

configVersionToSave := upgradeVersions.ConfigVersion
certVersionToSave := upgradeVersions.CertVersion

missingPkgs := []string{}
if swType != "" {
if objIds != nil {
Expand Down Expand Up @@ -264,6 +267,9 @@ func (w *DownloadWorker) DownloadAgentUpgradePackages(org string, filePath strin
glog.Errorf(dwlog(fmt.Sprintf("No config upgrade object found of expected type %v found in manifest list.", HZN_CONFIG_FILE)))
missingPkgs = append(missingPkgs, HZN_CONFIG_FILE)
}
} else {
// no need to update config, then will keep current config version
configVersionToSave = dev.SoftwareVersions[persistence.CONFIG_VERSION]
}

if certType != "" {
Expand All @@ -283,13 +289,16 @@ func (w *DownloadWorker) DownloadAgentUpgradePackages(org string, filePath strin
glog.Errorf(dwlog(fmt.Sprintf("No cert upgrade object found of expected type %v found in manifest list.", HZN_CERT_FILE)))
missingPkgs = append(missingPkgs, HZN_CERT_FILE)
}
} else {
// no need to update cert, then will keep current cert version
certVersionToSave = dev.SoftwareVersions[persistence.CERT_VERSION]
}

latestVersions := checkForLatestKeywords(manifest)

// Return the software version regardless of whether or not it was upgraded as this version is set in the software
// The config and cert versions should be the actual version downloaded so after the upgrade is executed, these versions can be used to set the device versions
versionsToSave := exchangecommon.AgentUpgradeVersions{SoftwareVersion: manifestUpgradeVersions.SoftwareVersion, ConfigVersion: upgradeVersions.ConfigVersion, CertVersion: upgradeVersions.CertVersion}
versionsToSave := exchangecommon.AgentUpgradeVersions{SoftwareVersion: manifestUpgradeVersions.SoftwareVersion, ConfigVersion: configVersionToSave, CertVersion: certVersionToSave}

if swType == "" && configType == "" && certType == "" {
w.Messages() <- events.NewNMPDownloadCompleteMessage(events.NMP_DOWNLOAD_COMPLETE, exchangecommon.STATUS_NO_ACTION, "", nmpName, &versionsToSave, latestVersions)
Expand Down Expand Up @@ -662,3 +671,4 @@ func insertVersionToCert(filePath string, nmpName string, version string) error
func dwlog(input string) string {
return fmt.Sprintf("Download worker: %v", input)
}

25 changes: 23 additions & 2 deletions exchange/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,13 @@ func UpdateCacheNodePutWriteThru(nodeOrg string, nodeId string, cachedDevice *De
pdr.UserInput = nil
pdr.SoftwareVersions = SoftwareVersion{}

if !reflect.DeepEqual(*pdr, PutDeviceRequest{}) {
// Setting this line to prevent unexpected unequal from !reflect.DeepEqual(*pdr, emptyPdr).
// type of pdr.SoftwareVersions is SoftwareVersion{}, type of PatchDeviceRequest{} is SoftwareVersion(nil) without setting this line
// For debugging, use %#v instead of %v in the log
emptyPdr := PutDeviceRequest{
SoftwareVersions: SoftwareVersion{},
}
if !reflect.DeepEqual(*pdr, emptyPdr) {
// If you see this error, most likely a new field has been added to the PutDeviceRequest struct and this function needs to be updated to accomadate it
glog.Errorf("Warning: Failed to completely update the cached device %s/%s. Changed fields present in the put request were not applied to the cached device. Dropping cache and continuing.", nodeOrg, nodeId)
DeleteCacheResource(NODE_DEF_TYPE_CACHE, NodeCacheMapKey(nodeOrg, nodeId))
Expand All @@ -381,6 +387,14 @@ func UpdateCacheNodePatchWriteThru(nodeOrg string, nodeId string, cachedDevice *
cachedDevice.Arch = *pdr.Arch
pdr.Arch = nil
}
if pdr.ClusterNamespace != nil && *pdr.ClusterNamespace != "" {
cachedDevice.ClusterNamespace = *pdr.ClusterNamespace
pdr.ClusterNamespace = nil
}
if pdr.IsNamespaceScoped != nil {
cachedDevice.IsNamespaceScoped = *pdr.IsNamespaceScoped
pdr.IsNamespaceScoped = nil
}
if pdr.RegisteredServices != nil {
cachedDevice.RegisteredServices = *pdr.RegisteredServices
pdr.RegisteredServices = nil
Expand All @@ -390,7 +404,14 @@ func UpdateCacheNodePatchWriteThru(nodeOrg string, nodeId string, cachedDevice *
pdr.SoftwareVersions = SoftwareVersion{}
}
}
if !reflect.DeepEqual(*pdr, PatchDeviceRequest{}) {

// Setting this line to prevent unexpected unequal from !reflect.DeepEqual(*pdr, emptyPdr).
// type of pdr.SoftwareVersions is SoftwareVersion{}, type of PatchDeviceRequest{} is SoftwareVersion(nil) without setting this line
// For debugging, use %#v instead of %v in the log
emptyPdr := PatchDeviceRequest{
SoftwareVersions: SoftwareVersion{},
}
if !reflect.DeepEqual(*pdr, emptyPdr) {
// If you see this error, most likely a new field has been added to the PatchDeviceRequest struct and this function needs to be updated to accomadate it
glog.Errorf("Warning: Failed to completely update the cached device %s/%s. Changed fields present in the patch request were not applied to the cached device. Dropping cache and continuing.", nodeOrg, nodeId)
DeleteCacheResource(NODE_DEF_TYPE_CACHE, NodeCacheMapKey(nodeOrg, nodeId))
Expand Down
2 changes: 1 addition & 1 deletion exchange/node_management_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func GetAllExchangeNodeManagementPolicy(ec ExchangeContext, policyOrg string) (*

// Get lists of the agent file versions currently availible in the css
func GetNodeUpgradeVersions(ec ExchangeContext) (*exchangecommon.AgentFileVersions, error) {
glog.V(3).Infof("Getting the availible versions for agent upgrade packages from the exchange.")
glog.V(3).Infof("Getting the available versions for agent upgrade packages from the exchange.")

var resp interface{}
resp = new(exchangecommon.AgentFileVersions)
Expand Down
6 changes: 5 additions & 1 deletion nodemanagement/agent_upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ func (n *NodeManagementWorker) HandleAgentFilesVersionChange(cmd *AgentFileVersi
}
}

// set the status to waiting for this nmp
// set the status to waiting, clear out the SetActualStartTime and CompletionTime for this nmp
if setStatusToWaiting {
glog.V(3).Infof(nmwlog(fmt.Sprintf("Change status to \"waiting\" for the nmp %v", statusName)))

Expand All @@ -344,6 +344,8 @@ func (n *NodeManagementWorker) HandleAgentFilesVersionChange(cmd *AgentFileVersi
}

status.AgentUpgrade.Status = exchangecommon.STATUS_NEW
status.SetActualStartTime("")
status.SetCompletionTime("")
err = n.UpdateStatus(statusName, status, exchange.GetPutNodeManagementPolicyStatusHandler(n), persistence.NewMessageMeta(EL_NMP_STATUS_CHANGED, statusName, exchangecommon.STATUS_NEW), persistence.EC_NMP_STATUS_UPDATE_NEW)
if err != nil {
glog.Errorf(nmwlog(fmt.Sprintf("Error changing nmp status for %v to \"waiting\". Error was %v.", statusName, err)))
Expand Down Expand Up @@ -385,6 +387,8 @@ func (w *NodeManagementWorker) HandleNmpStatusReset() {
glog.V(3).Infof(nmwlog(fmt.Sprintf("Change status from \"reset\" to \"waiting\" for the nmp %v", nmp_name)))

local_status.AgentUpgrade.Status = exchangecommon.STATUS_NEW
local_status.SetActualStartTime("")
local_status.SetCompletionTime("")
if local_status.AgentUpgradeInternal != nil {
local_status.AgentUpgradeInternal.DownloadAttempts = 0
}
Expand Down

0 comments on commit dc79f63

Please sign in to comment.