Skip to content

Commit

Permalink
fix(docker/titus): switch registry when changing accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
anotherchrisberry committed Feb 24, 2017
1 parent 47e7ddd commit 19da1fe
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export class DockerImageAndTagSelectorController implements ng.IComponentControl
private organizationMap: { [key: string]: string[] };
private repositoryMap: { [key: string]: string[] };
private registryMap: { [key: string]: string };
private imageLoader: ng.IPromise<any>;

public labelClass: string;
public fieldClass: string;
Expand Down Expand Up @@ -60,7 +61,6 @@ export class DockerImageAndTagSelectorController implements ng.IComponentControl
});
}
}

this.organizations = this.accountMap[this.showRegistry ? this.account : this.registry] || [];
if (!this.organizations.includes(this.organization)) {
this.organization = null;
Expand Down Expand Up @@ -180,24 +180,27 @@ export class DockerImageAndTagSelectorController implements ng.IComponentControl
account: this.showRegistry ? this.account : this.registry
};

if (!this.viewState.imagesLoading) {
this.viewState.imagesLoading = true;
this.dockerImageReader.findImages(imageConfig).then((images: IDockerImage[]) => {
this.updateRegistryMap(images);
this.updateAccountMap(images);
this.accounts = this.accounts || Object.keys(this.accountMap);

this.updateOrganizationMap(images);
this.organizations.push(...Object.keys(this.organizationMap));
this.updateRepositoryMap(images);
this.updateOrganizationsList();

this.viewState.imagesLoaded = true;
}).finally(() => {
this.viewState.imagesLoading = false;
this.viewState.imagesRefreshing = false;
});
}
this.viewState.imagesLoading = true;
const imageLoader = this.dockerImageReader.findImages(imageConfig).then((images: IDockerImage[]) => {
if (this.imageLoader !== imageLoader) {
// something else is getting loaded
return;
}
this.updateRegistryMap(images);
this.updateAccountMap(images);
this.accounts = this.accounts || Object.keys(this.accountMap);

this.updateOrganizationMap(images);
this.organizations.push(...Object.keys(this.organizationMap));
this.updateRepositoryMap(images);
this.updateOrganizationsList();

this.viewState.imagesLoaded = true;
}).finally(() => {
this.viewState.imagesLoading = false;
this.viewState.imagesRefreshing = false;
});
this.imageLoader = imageLoader;
}

private uniqMapEntries(map: { [key: string]: string[] }): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ module.exports = angular.module('spinnaker.core.pipeline.stage.titus.runJobStage

this.accountChanged = () => {
this.accountChangedStream.next(null);
setRegistry();
this.updateRegions();

};
Expand All @@ -66,6 +67,12 @@ module.exports = angular.module('spinnaker.core.pipeline.stage.titus.runJobStage
stage.registry = changes.registry;
};

function setRegistry() {
if (stage.credentials) {
stage.registry = $scope.backingData.credentialsKeyedByAccount[stage.credentials].registry;
}
}

function updateImageId() {
if ($scope.stage.repository && $scope.stage.tag) {
$scope.stage.cluster.imageId = `${$scope.stage.repository}:${$scope.stage.tag}`;
Expand Down Expand Up @@ -133,7 +140,7 @@ module.exports = angular.module('spinnaker.core.pipeline.stage.titus.runJobStage
stage.credentials = backingData.credentials[0];
}

stage.registry = backingData.credentialsKeyedByAccount[stage.credentials].registry;
setRegistry();
return $q.all([]).then(() => {
vm.updateRegions();
this.loaded = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ module.exports = angular.module('spinnaker.serverGroup.configure.titus.configura
var backingData = command.backingData;
configureZones(command);
if (command.credentials) {
command.registry = backingData.credentialsKeyedByAccount[command.credentials].registry;
backingData.filtered.regions = backingData.credentialsKeyedByAccount[command.credentials].regions;
if (!backingData.filtered.regions.some(r => r.name === command.region)) {
command.region = null;
Expand Down

0 comments on commit 19da1fe

Please sign in to comment.