Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into add-namespace-metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
olevitt committed Jun 19, 2024
2 parents 559d440 + 78bb38b commit 8088ff6
Show file tree
Hide file tree
Showing 15 changed files with 472 additions and 88 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ jobs:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v5
uses: docker/build-push-action@v6
with:
context: onyxia-api
platforms: linux/amd64,linux/arm64
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ public class CatalogWrapper {
@Schema(description = "Catalog id")
private String id;

@Schema(description = "Catalog name")
private String name;
@Schema(description = "Localized string for the name of the catalog")
private Object name;

@Schema(description = "Description of the catalog")
private String description;
@Schema(description = "Localized string for the description of the catalog")
private Object description;

@Schema(description = "Who maintains the catalog")
private String maintainer;
Expand Down Expand Up @@ -127,11 +127,11 @@ public void setId(String id) {
this.id = id;
}

public String getName() {
public Object getName() {
return name;
}

public void setName(String name) {
public void setName(Object name) {
this.name = name;
}

Expand All @@ -143,11 +143,11 @@ public void setLocation(String location) {
this.location = location;
}

public String getDescription() {
public Object getDescription() {
return description;
}

public void setDescription(String description) {
public void setDescription(Object description) {
this.description = description;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,42 @@ public class CompatibilityChecks {
private static final Logger LOGGER = LoggerFactory.getLogger(CompatibilityChecks.class);
private final RegionsConfiguration regionsConfiguration;
private final KubernetesClientProvider kubernetesClientProvider;

private final HelmVersionService helmVersionService;
private final Runnable exitHandler;

@Autowired
public CompatibilityChecks(
RegionsConfiguration regionsConfiguration,
KubernetesClientProvider kubernetesClientProvider,
HelmVersionService helmVersionService) {
this(
regionsConfiguration,
kubernetesClientProvider,
helmVersionService,
() -> System.exit(0));
}

public CompatibilityChecks(
RegionsConfiguration regionsConfiguration,
KubernetesClientProvider kubernetesClientProvider,
HelmVersionService helmVersionService,
Runnable exitHandler) {
this.regionsConfiguration = regionsConfiguration;
this.kubernetesClientProvider = kubernetesClientProvider;
this.helmVersionService = helmVersionService;
this.exitHandler = exitHandler;
}

@EventListener(ContextRefreshedEvent.class)
public void checkHelm() {
try {
LOGGER.info("Using helm {}", helmVersionService.getVersion());
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
LOGGER.error("Thread was interrupted while determining helm version", e);
} catch (Exception e) {
LOGGER.error("Could not determine helm version", e);
System.exit(0);
exitHandler.run();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,43 +211,56 @@ private void suspendOrResume(Region region, Project project, String serviceId, b
int split = chart.lastIndexOf('-');
String chartName = chart.substring(0, split);
String version = chart.substring(split + 1);
List<CatalogWrapper> elligibleCatalogs =
catalogService.getCatalogs(region, user).getCatalogs().stream()
.filter(
catalog ->
catalog.getCatalog()
.getPackageByNameAndVersion(chartName, version)
.isPresent())
.toList();
if (elligibleCatalogs.isEmpty()) {
throw new NotFoundException();
String catalogId = userService.getCatalogId();
// This code is for legacy compat for services that were created with Onyxia < v2.7.0
// before introduction of Onyxia's secret
if (catalogId == null) {
List<CatalogWrapper> elligibleCatalogs =
catalogService.getCatalogs(region, user).getCatalogs().stream()
.filter(
catalog ->
catalog.getCatalog()
.getPackageByName(chartName)
.isPresent())
.toList();
if (elligibleCatalogs.isEmpty()) {
throw new NotFoundException();
}
if (elligibleCatalogs.size() > 1) {
throw new IllegalStateException("Chart is present in multiple catalogs, abort");
}
CatalogWrapper catalog = elligibleCatalogs.getFirst();
catalogId = catalog.getId();
}
if (elligibleCatalogs.size() > 1) {
throw new IllegalStateException("Chart is present in multiple catalogs, abort");
Optional<CatalogWrapper> catalog = catalogService.getCatalogById(catalogId);
if (catalog.isEmpty()) {
throw new IllegalStateException(
"Catalog " + catalogId + " is not available anymore");
}
CatalogWrapper catalog = elligibleCatalogs.getFirst();
Pkg pkg = catalog.getCatalog().getPackageByNameAndVersion(chartName, version).get();

if (suspend) {
helmAppsService.suspend(
region,
project,
catalog.getId(),
pkg,
catalog.get().getId(),
chartName,
version,
user,
serviceId,
catalog.getSkipTlsVerify(),
catalog.getCaFile(),
catalog.get().getSkipTlsVerify(),
catalog.get().getCaFile(),
false);
} else {
helmAppsService.resume(
region,
project,
catalog.getId(),
pkg,
catalog.get().getId(),
chartName,
version,
user,
serviceId,
catalog.getSkipTlsVerify(),
catalog.getCaFile(),
catalog.get().getSkipTlsVerify(),
catalog.get().getCaFile(),
false);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,41 +36,69 @@ public CatalogRefresher(
this.refreshTime = refreshTime;
}

private void refresh() {
private void refreshCatalogs() {
catalogs.getCatalogs()
.forEach(
c -> {
try {
LOGGER.info(
helmRepoService.addHelmRepo(
c.getLocation(),
c.getId(),
c.getSkipTlsVerify(),
c.getCaFile()));
LOGGER.info("Adding Helm Repo: {}", c.getId());
helmRepoService.addHelmRepo(
c.getLocation(),
c.getId(),
c.getSkipTlsVerify(),
c.getCaFile());
LOGGER.info("Updating catalog: {}", c.getId());
catalogLoader.updateCatalog(c);
} catch (Exception e) {
LOGGER.warn("Exception occurred", e);
LOGGER.warn(
"Exception occurred while updating catalog: {}",
c.getId(),
e);
}
});
}

private void updateRepo() throws InterruptedException {
try {
LOGGER.info("Updating Helm Repo Service...");
helmRepoService.repoUpdate();
} catch (InterruptedException | TimeoutException | IOException e) {
LOGGER.warn("Exception occurred", e);
} catch (InterruptedException e) {
LOGGER.warn("InterruptedException occurred during repoUpdate", e);
Thread.currentThread().interrupt();
throw e;
} catch (TimeoutException | IOException e) {
LOGGER.warn("Exception occurred during repoUpdate", e);
}
}

private void refresh() throws InterruptedException {
updateRepo();
refreshCatalogs();
}

@Override
public void run(ApplicationArguments args) throws Exception {
this.refresh();
LOGGER.info("Starting catalog refresher...");
try {
refresh();
} catch (InterruptedException e) {
LOGGER.warn("Run method interrupted", e);
Thread.currentThread().interrupt();
}

if (refreshTime > 0L) {
Timer timer = new Timer();
TimerTask timerTask =
new TimerTask() {
@Override
public void run() {
LOGGER.info("Refreshing catalogs");
refresh();
try {
refresh();
} catch (InterruptedException e) {
LOGGER.warn("Timer task interrupted", e);
Thread.currentThread().interrupt();
}
}
};
timer.scheduleAtFixedRate(timerTask, refreshTime, refreshTime);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ void resume(
Region region,
Project project,
String catalogId,
Pkg pkg,
String chartName,
String version,
User user,
String serviceId,
boolean skipTlsVerify,
Expand All @@ -76,7 +77,8 @@ void suspend(
Region region,
Project project,
String catalogId,
Pkg pkg,
String chartName,
String version,
User user,
String serviceId,
boolean skipTlsVerify,
Expand Down
Loading

0 comments on commit 8088ff6

Please sign in to comment.