diff --git a/kotsadm/api/src/kots_app/kots_app.ts b/kotsadm/api/src/kots_app/kots_app.ts index ba4cef3989..1ae6887c8f 100644 --- a/kotsadm/api/src/kots_app/kots_app.ts +++ b/kotsadm/api/src/kots_app/kots_app.ts @@ -507,7 +507,7 @@ export class KotsApp { return false; } const registryInfo = await stores.kotsAppStore.getAppRegistryDetails(this.id); - const rendered = await kotsRenderFile(this, stores, tmpl, registryInfo); + const rendered = await kotsRenderFile(this, this.currentSequence!, tmpl, registryInfo); const backup = yaml.safeLoad(rendered); const annotations = _.get(backup, "metadata.annotations") as any; if (!_.isPlainObject(annotations)) { diff --git a/kotsadm/api/src/kots_app/kots_ffi.ts b/kotsadm/api/src/kots_app/kots_ffi.ts index 6b5ca29979..61a8c06899 100644 --- a/kotsadm/api/src/kots_app/kots_ffi.ts +++ b/kotsadm/api/src/kots_app/kots_ffi.ts @@ -199,7 +199,7 @@ export async function kotsAppDownloadUpdateFromAirgap(airgapFile: string, app: K } } -export async function kotsRenderFile(app: KotsApp, stores: Stores, input: string, registryInfo: KotsAppRegistryDetails): Promise { +export async function kotsRenderFile(app: KotsApp, sequence: number, input: string, registryInfo: KotsAppRegistryDetails): Promise { const filename = tmp.tmpNameSync(); fs.writeFileSync(filename, input); @@ -208,7 +208,7 @@ export async function kotsRenderFile(app: KotsApp, stores: Stores, input: string const archive = path.join(tmpDir.name, "archive.tar.gz"); try { - fs.writeFileSync(archive, await app.getArchive("" + (app.currentSequence!))); + fs.writeFileSync(archive, await app.getArchive("" + sequence)); const statusServer = new StatusServer(); await statusServer.start(tmpDir.name); diff --git a/kotsadm/api/src/snapshots/backup.ts b/kotsadm/api/src/snapshots/backup.ts index 3c53bf730c..251212d83e 100644 --- a/kotsadm/api/src/snapshots/backup.ts +++ b/kotsadm/api/src/snapshots/backup.ts @@ -36,7 +36,7 @@ export async function backup(stores: Stores, appId: string, scheduled: boolean): } const tmpl = await stores.snapshotsStore.getKotsBackupSpec(appId, deployedVersion.sequence); - const rendered = await kotsRenderFile(app, stores, tmpl, registryInfo); + const rendered = await kotsRenderFile(app, app.currentSequence!, tmpl, registryInfo); const base = yaml.safeLoad(rendered) as Backup; const spec = (base && base.spec) || {}; diff --git a/kotsadm/api/src/sockets/kots/DeploySocket.ts b/kotsadm/api/src/sockets/kots/DeploySocket.ts index f2284906aa..8cfa54b75b 100644 --- a/kotsadm/api/src/sockets/kots/DeploySocket.ts +++ b/kotsadm/api/src/sockets/kots/DeploySocket.ts @@ -3,7 +3,7 @@ import { IO, Nsp, SocketService, SocketSession, Socket } from "@tsed/socketio"; import { getPostgresPool } from "../../util/persistence/db"; import { KotsAppStore, UndeployStatus } from "../../kots_app/kots_app_store"; import { KotsAppStatusStore } from "../../kots_app/kots_app_status_store"; -import { State, KotsApp } from "../../kots_app"; +import { State, KotsApp, kotsRenderFile } from "../../kots_app"; import { Params } from "../../server/params"; import { ClusterStore, Cluster } from "../../cluster"; import { PreflightStore } from "../../preflight/preflight_store"; @@ -302,9 +302,18 @@ export class KotsDeploySocketService { try { const kotsAppSpec = await app.getKotsAppSpec(cluster.id, this.kotsAppStore) if (kotsAppSpec && kotsAppSpec.statusInformers) { + // render status informers + const registryInfo = await this.kotsAppStore.getAppRegistryDetails(app.id); + const renderedInformers: string[] = []; + for (let i = 0; i < kotsAppSpec.statusInformers.length; i++) { + const informer = kotsAppSpec.statusInformers[i]; + const rendered = await kotsRenderFile(app, deployedAppSequence, informer, registryInfo); + renderedInformers.push(rendered); + } + // send to kots operator this.io.in(clusterSocketHistory.clusterId).emit("appInformers", { app_id: app.id, - informers: kotsAppSpec.statusInformers, + informers: renderedInformers, }); } else { // no informers, set state to ready diff --git a/kotsadm/operator/pkg/client/client.go b/kotsadm/operator/pkg/client/client.go index fa7a0ec26c..847281b646 100644 --- a/kotsadm/operator/pkg/client/client.go +++ b/kotsadm/operator/pkg/client/client.go @@ -302,9 +302,7 @@ func (c *Client) registerHandlers(socketClient *socket.Client) error { err = socketClient.On("appInformers", func(h *socket.Channel, args InformRequest) { log.Printf("received an inform event: %#v", args) - if err := c.applyAppInformers(args.AppID, args.Informers); err != nil { - log.Printf("error running informer: %s", err.Error()) - } + c.applyAppInformers(args.AppID, args.Informers) }) if err != nil { return errors.Wrap(err, "failed to add inform handler") @@ -414,17 +412,22 @@ func runPreflight(preflightURI string, ignorePermissions bool) error { return kubernetesApplier.Preflight(preflightURI, ignorePermissions) } -func (c *Client) applyAppInformers(appID string, informerStrings []types.StatusInformerString) error { +func (c *Client) applyAppInformers(appID string, informerStrings []types.StatusInformerString) { var informers []types.StatusInformer for _, str := range informerStrings { + if str == "" { + continue + } informer, err := str.Parse() if err != nil { - return errors.Wrapf(err, "failed to parse informer %s", str) + log.Printf(fmt.Sprintf("failed to parse informer %s: %s", str, err.Error())) + continue // don't stop } informers = append(informers, informer) } - c.appStateMonitor.Apply(appID, informers) - return nil + if len(informers) > 0 { + c.appStateMonitor.Apply(appID, informers) + } } func (c *Client) sendAppStatus(appStatus types.AppStatus) error {