Skip to content

Support upgrading the cluster extensions #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
May 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.3.6
0.3.7
4 changes: 2 additions & 2 deletions deploy/charts/app-orch-tenant-controller/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
apiVersion: v2
description: Tenant Controller
name: app-orch-tenant-controller
version: 0.3.6
version: 0.3.7
annotations:
revision: ""
created: ""
appVersion: "0.3.6"
appVersion: "0.3.7"
2 changes: 1 addition & 1 deletion deploy/charts/app-orch-tenant-controller/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ configProvisioner:
releaseServiceRootUrl: "oci://registry-rs.edgeorchestration.intel.com"
releaseServiceProxyRootUrl: "oci://rs-proxy.rs-proxy.svc.cluster.local:8443"
manifestPath: "/edge-orch/en/file/cluster-extension-manifest"
manifestTag: "v1.0.36"
manifestTag: "v1.1.2"

httpProxy: ""
httpsProxy: ""
Expand Down
4 changes: 4 additions & 0 deletions internal/manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,10 @@ func (m *Manager) Close() {
close(m.eventChan)
}

func (m *Manager) ManifestTag() string {
return m.Config.ManifestTag
}

// HealthCheck is a struct receiver implementing onos northbound Register interface.
type HealthCheck struct{}

Expand Down
10 changes: 10 additions & 0 deletions internal/nexus/nexus-abstract.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ type NexusFolderInterface interface { // nolint:revive
type NexusProjectActiveWatcherInterface interface { // nolint:revive
Update(ctx context.Context) error
GetSpec() *projectActiveWatcherv1.ProjectActiveWatcherSpec
GetAnnotations() map[string]string
SetAnnotations(annotations map[string]string)
DisplayName() string
}

Expand Down Expand Up @@ -65,6 +67,14 @@ func (w *NexusProjectActiveWatcher) GetSpec() *projectActiveWatcherv1.ProjectAct
return &w.Spec
}

func (w *NexusProjectActiveWatcher) GetAnnotations() map[string]string {
return (*nexus.ProjectactivewatcherProjectActiveWatcher)(w).GetAnnotations()
}

func (w *NexusProjectActiveWatcher) SetAnnotations(annotations map[string]string) {
(*nexus.ProjectactivewatcherProjectActiveWatcher)(w).SetAnnotations(annotations)
}

func (w *NexusProjectActiveWatcher) DisplayName() string {
return (*nexus.ProjectactivewatcherProjectActiveWatcher)(w).DisplayName()
}
Expand Down
50 changes: 44 additions & 6 deletions internal/nexus/nexus-hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import (
"time"
)

var log = dazl.GetPackageLogger()

const (
appName = "config-provisioner"

Expand All @@ -28,13 +30,14 @@ const (
MaxOrganizationNameLength = 63 // Same limit as used in tenant data model
MaxProjectNameLength = 63 // Same limit as used in tenant data model
MaxProjectUUIDLength = 36
// manifest tag annotation key
ManifestTagAnnotationKey = "app-orch-tenant-controller/manifest-tag"
)

var log = dazl.GetPackageLogger()

type ProjectManager interface {
CreateProject(orgName string, projectName string, projectUUID string, project NexusProjectInterface)
DeleteProject(orgName string, projectName string, projectUUID string, project NexusProjectInterface)
ManifestTag() string
}

type Hook struct {
Expand Down Expand Up @@ -86,6 +89,7 @@ func (h *Hook) Subscribe() error {
return err
}
log.Info("Nexus hook successfully subscribed")

return nil
}

Expand Down Expand Up @@ -177,6 +181,22 @@ func (h *Hook) SetWatcherStatusInProgress(proj NexusProjectInterface, message st
return err
}

func (h *Hook) UpdateProjectManifestTag(proj NexusProjectInterface) error {
log.Infof("Setting watcher manifest tag for project %s to %s", proj.DisplayName(), h.dispatcher.ManifestTag())
watcherObj, err := proj.GetActiveWatchers(context.Background(), appName)
if err != nil {
return err
}
if watcherObj != nil {
log.Debug("Setting watcher annotations")
annotations := make(map[string]string)
annotations[ManifestTagAnnotationKey] = h.dispatcher.ManifestTag()
watcherObj.SetAnnotations(annotations)
return watcherObj.Update(context.Background())
}
return err
}

func (h *Hook) StopWatchingProject(project NexusProjectInterface) {
ctx, cancel := context.WithTimeout(context.Background(), nexusTimeout)
defer cancel()
Expand Down Expand Up @@ -296,14 +316,32 @@ func (h *Hook) projectCreated(project NexusProjectInterface) error {
TimeStamp: h.safeUnixTime(),
},
})

if err != nil {
log.Errorf("Failed to create ProjectActiveWatcher object with an error: %v", err)
return err
}

var action string

if watcherObj.GetSpec().StatusIndicator == projectActiveWatcherv1.StatusIndicationIdle && watcherObj.GetSpec().Message == "Created" {
// This is a rerun of an event we already processed - no more processing required
// This is a rerun of an event we already processed - check for update
log.Infof("Watch %s for project %s already provisioned", watcherObj.DisplayName(), project.DisplayName())
return nil
log.Debugf("existing watcher annotations are: %+v", watcherObj.GetAnnotations())
annotations := watcherObj.GetAnnotations()
if annotations[ManifestTagAnnotationKey] == h.dispatcher.ManifestTag() {
// Manifest tag is correct
log.Infof("Manifest tag is correct, no need to update")
return nil
}
log.Infof("Manifest tag is not correct, updating. Have %s, want %s", annotations[ManifestTagAnnotationKey], h.dispatcher.ManifestTag())
action = "update"
} else {
action = "created"
}

if nexus.IsAlreadyExists(err) {
log.Warnf("Watch %s already exists for project %s", watcherObj.DisplayName(), project.DisplayName())
log.Infof("Watch %s already exists for project %s", watcherObj.DisplayName(), project.DisplayName())
} else if err != nil {
// NOTE: This will permantently fail project creation -- there is no recovery if we cannot create the watcher.
return fmt.Errorf("Error %+v while creating watch %s for project %s", err, appName, project.DisplayName())
Expand All @@ -318,7 +356,7 @@ func (h *Hook) projectCreated(project NexusProjectInterface) error {
}
h.dispatcher.CreateProject(organizationName, project.DisplayName(), project.GetUID(), project)

log.Infof("Active watcher %s created for Project %s", watcherObj.DisplayName(), project.DisplayName())
log.Infof("Active watcher %s %s created for Project %s", watcherObj.DisplayName(), action, project.DisplayName())

return nil
}
Expand Down
4 changes: 4 additions & 0 deletions internal/nexus/nexus-hook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ func (m *MockProjectManager) DeleteProject(orgName string, projectName string, p
m.deleted = append(m.deleted, projectName)
}

func (m *MockProjectManager) ManifestTag() string {
return ""
}

type NexusHookTestSuite struct {
suite.Suite
}
Expand Down
17 changes: 15 additions & 2 deletions internal/plugins/extensions-provisioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type Manifest struct {
}

type AppDeployment interface {
ListDeployments(ctx context.Context) error
ListDeploymentNames(ctx context.Context, projectID string) (map[string]string, error)
CreateDeployment(ctx context.Context, dpName string, displayName string, version string, profileName string, projectID string, labels map[string]string) error
}

Expand Down Expand Up @@ -87,7 +87,7 @@ func (p *ExtensionsProvisionerPlugin) waitForADM(ctx context.Context) {
var cancel context.CancelFunc
var lctx context.Context
lctx, cancel = context.WithTimeout(ctx, 10*time.Second)
err := ad.ListDeployments(lctx)
_, err := ad.ListDeploymentNames(lctx, "")
cancel()
if err == nil || strings.Contains(err.Error(), "Unauthenticated") {
break
Expand Down Expand Up @@ -176,7 +176,20 @@ func (p *ExtensionsProvisionerPlugin) CreateEvent(ctx context.Context, event Eve
} else {
uuid := event.UUID
ad, _ := AppDeploymentFactory(p.configuration)

existingDisplayNames, err := ad.ListDeploymentNames(ctx, uuid)
if err != nil {
log.Info("Not able to list deployments, skipping deployments")
return err
}

for _, dl := range manifest.Lpke.DeploymentList {
log.Infof("displayName: %s", dl.DisplayName)
if _, exists := existingDisplayNames[dl.DisplayName]; exists {
log.Infof("Deployment with displayName %s already exists, skipping creation", dl.DisplayName)
continue
}

labels := map[string]string{}
for _, appTargetCluster := range dl.AllAppTargetClusters {
labels[appTargetCluster.Key] = appTargetCluster.Val
Expand Down
5 changes: 3 additions & 2 deletions internal/plugins/mock-clients_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,9 @@ func newTestADM(_ config.Configuration) (AppDeployment, error) {
return mockADM, nil
}

func (t *testADM) ListDeployments(_ context.Context) error {
return nil
func (t *testADM) ListDeploymentNames(_ context.Context, _ string) (map[string]string, error) {
displayName := make(map[string]string)
return displayName, nil
}

type mockDeployment struct {
Expand Down
8 changes: 8 additions & 0 deletions internal/plugins/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ func Dispatch(ctx context.Context, event Event, hook *nexushook.Hook) error {
}
}
log.Infof("Done dispatching event: %v", event)
if event.EventType == "create" {
if hook != nil {
err = hook.UpdateProjectManifestTag(event.Project)
if err != nil {
return err
}
}
}
return nil
}

Expand Down
22 changes: 17 additions & 5 deletions internal/southbound/app-deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,25 @@ func newADM(configuration config.Configuration) (*AppDeployment, error) {
return ad, nil
}

func (a *AppDeployment) ListDeployments(ctx context.Context) error {
ctx, err := getCtxForProjectID(ctx, "", a.configuration)
func (a *AppDeployment) ListDeploymentNames(ctx context.Context, projectID string) (map[string]string, error) {
ctx, err := getCtxForProjectID(ctx, projectID, a.configuration)
if err != nil {
return err
return nil, err
}
admResp, err := a.admClient.ListDeployments(ctx, &adm.ListDeploymentsRequest{})
if err != nil {
return nil, err
}

existingDeployments := admResp.GetDeployments()
existingDisplayNames := make(map[string]string)
for _, dep := range existingDeployments {
log.Infof("displayName : %s", dep.DisplayName)
existingDisplayNames[dep.DisplayName] = dep.DisplayName
}
_, err = a.admClient.ListDeployments(ctx, &adm.ListDeploymentsRequest{})
return err

log.Infof("display name list size : %d", len(existingDisplayNames))
return existingDisplayNames, nil
}

func (a *AppDeployment) CreateDeployment(ctx context.Context,
Expand Down
2 changes: 1 addition & 1 deletion internal/southbound/app-deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func (s *AppDeploymentTestSuite) TestAppDeployment() {
ADM, err := newADM(config.Configuration{AdmServer: ""})
s.NoError(err)

err = ADM.ListDeployments(s.ctx)
_, err = ADM.ListDeploymentNames(s.ctx, "")
s.NoError(err)

labels1 := map[string]string{
Expand Down
2 changes: 1 addition & 1 deletion internal/southbound/catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func (c *AppCatalog) ListRegistries(ctx context.Context) error {
}

func (c *AppCatalog) UploadYAMLFile(ctx context.Context, projectUUID string, fileName string, artifact []byte, lastFile bool) error {
log.Infof("Uploading file %s to %s last file %t", fileName, projectUUID, lastFile)
log.Debugf("Uploading file %s to %s last file %t", fileName, projectUUID, lastFile)
ctx, err := getCtxForProjectID(ctx, projectUUID, c.config)
if err != nil {
return err
Expand Down
Loading