Skip to content

Commit

Permalink
Add support for Artifact Hub (#4646)
Browse files Browse the repository at this point in the history
* Add support for Artifact Hub

* Remove monocular handlers

* Rename Helm Hub in UI. Add commnets to go code

* Complete rename of Helm Hub. Add cache cleanup

* Fix mwerge conflict

* Remove todo and unused method

* Remove unused API

* Add comment

* Update flag

* Fix typo

* Fix upgrade issue when comparing charts on ArtifactHub

* Fix relative charts

* Fix cache paths to include repo name

* Fix url joining and icon content type
  • Loading branch information
nwmac authored Oct 9, 2020
1 parent f3547a5 commit e795104
Show file tree
Hide file tree
Showing 13 changed files with 706 additions and 223 deletions.
4 changes: 2 additions & 2 deletions deploy/kubernetes/console/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,8 @@ spec:
value: "{{.Values.kube.registry.hostname}}/{{.Values.kube.organization}}/stratos-kube-terminal:{{.Values.consoleVersion}}"
- name: STRATOS_KUBERNETES_DASHBOARD_IMAGE
value: "{{.Values.console.kubeDashboardImage}}"
- name: HELM_HUB_ENABLED
value: {{ default "false" .Values.console.helmHubEnabled | quote }}
- name: ARTIFACT_HUB_ENABLED
value: {{ default "true" .Values.console.artifactHubEnabled | quote }}
{{- include "stratosJetstreamEnv" . | indent 8 }}
readinessProbe:
httpGet:
Expand Down
4 changes: 2 additions & 2 deletions deploy/kubernetes/console/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ console:
# Download link when installing the Kubernetes Dashboard in a targetted Kube Endpoint
kubeDashboardImage:

# Enable Helm Hub
helmHubEnabled: false
# Enable Artifact Hub
artifactHubEnabled: true

# Size for analysis reports volume
reportsVolumeSize: 1Gi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ export function generateHelmEntities(): StratosBaseCatalogEntity[] {
},
{
type: HELM_HUB_ENDPOINT_TYPE,
label: 'Helm Hub',
labelPlural: 'Helm Hubs',
label: 'Artifact Hub',
labelPlural: 'Artifact Hubs',
authTypes: [],
unConnectable: true,
logoUrl: '/core/assets/custom/helm.svg',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<app-steppers cancel="/endpoints">
<app-step title="" [valid]="true" [onNext]="onNext" finishButtonText="Register">
<div>
<p>Helm Hub is a public repository for Helm Charts. </p>
<p>To browse and install these charts you need to register Helm Hub as an endpoint by clicking `Register` below.
<p>Artifact Hub is a public repository for Helm Charts.</p>
<p>To browse and install these charts you need to register Artifact Hub as an endpoint by clicking `Register` below.
</p>
<p>To disable Helm Hub simply unregister the Helm Hub endpoint</p>
<p>To disable Artifact Hub simply unregister the Artifact Hub endpoint</p>
</div>
</app-step>
</app-steppers>
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ export class HelmHubRegistrationComponent {
return stratosEntityCatalog.endpoint.api.register<ActionState>(
HELM_ENDPOINT_TYPE,
HELM_HUB_ENDPOINT_TYPE,
'Helm Hub',
'https://hub.helm.sh/api',
'Artifact Hub',
'https://artifacthub.io',
false
).pipe(
pairwise(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class ChartDetailsComponent implements OnInit {
this.chart = chart;
this.chartSubTitle = chart.attributes.repo.name;
if (getMonocularEndpoint(this.route, chart) !== stratosMonocularEndpointGuid) {
this.chartSubTitle = 'Helm Hub - ' + this.chartSubTitle;
this.chartSubTitle = 'Artifact Hub - ' + this.chartSubTitle;
}
const version = params.version || this.chart.relationships.latestChartVersion.data.version;
this.chartsService.getVersion(repo, chartName, version).pipe(first())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,6 @@ export class ChartsService {

// Get the URL for obtaining a Chart's schema
getChartSchemaURL(chartVersion: ChartVersion, name: string, repo: RepoAttributes): string {
// Helm Hub does not give us the schema information so we have to use an additional backend API to fetch the chart and check
if (chartVersion.attributes.schema === undefined) {
let url = this.getChartURL(chartVersion, repo);
url = btoa(url);
return `/pp/v1/monocular/schema/${name}/${url}`;
}

// We have the schema URL, so we can fetch that directly
return chartVersion.attributes.schema ? `${this.hostname}${chartVersion.attributes.schema}` : null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,13 +240,17 @@ export class HelmReleaseHelperService {
const updates = combineLatest(this.getCharts(), this.release$);
return updates.pipe(
map(([charts, release]) => {
let score = -1;
let match;
for (const c of charts) {
if (this.isProbablySameChart(c.attributes, release.chart.metadata)) {
const matchScore = this.compareCharts(c.attributes, release.chart.metadata);
if (matchScore > score) {
score = matchScore;
if (c.relationships && c.relationships.latestChartVersion && c.relationships.latestChartVersion.data) {
const latest = new Version(c.relationships.latestChartVersion.data.version);
const current = new Version(release.chart.metadata.version);
if (latest.isNewer(current)) {
return {
match = {
release,
upgrade: c.attributes,
version: c.relationships.latestChartVersion.data.version,
Expand All @@ -256,11 +260,15 @@ export class HelmReleaseHelperService {
}
}
}
// Did we find a matching chart? If so, return it
if (match) {
return match;
}
// No newer release, so return the release itself if that is what was requested and we can find the chart
// NOTE: If the helm repository is removed that we installed from, we won't be able to find the chart
if (returnLatest) {
// Need to check that the chart is probably the same
const releaseChart = charts.find(c => this.isProbablySameChart(c.attributes, release.chart.metadata) &&
const releaseChart = charts.find(c => this.compareCharts(c.attributes, release.chart.metadata) !== -1 &&
c.relationships.latestChartVersion.data.version === release.chart.metadata.version);
if (releaseChart) {
return {
Expand All @@ -278,10 +286,32 @@ export class HelmReleaseHelperService {

// We might have a chart with the same name in multiple repositories - we only have chart metadata
// We don't know which Helm repository it came from, so use the name and sources to match
private isProbablySameChart(a: ChartMetadata, b: ChartMetadata): boolean {
// Also uses the common words in the description and returns a weight
private compareCharts(a: ChartMetadata, b: ChartMetadata): number {
// Basic properties must be the same
if (a.name !== b.name) {
return false;
return -1;
}

// Find common words in the descriptions
const words = {};
for (let w of a.description.split(' ')) {
w = w.toLowerCase();
if (w.length > 3 && w !== 'helm' && w !== 'chart') {
words[w] = true
}
}

let common = 0;
for (let w of b.description.split(' ')) {
w = w.toLowerCase();
if(words[w]) {
common++;
}
}

if (!a.sources || !b.sources) {
return common;
}

// Must have at least one source in common
Expand All @@ -290,7 +320,7 @@ export class HelmReleaseHelperService {
count += b.sources.findIndex((s) => s === source) === -1 ? 0 : 1;
});

return count > 0;
return common + count * 100;
}

}
Expand Down
4 changes: 2 additions & 2 deletions src/jetstream/config.example
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,5 @@ INVITE_USER_CLIENT_SECRET=
# Cache folder for Helm Charts
# HELM_CACHE_FOLDER=./helm-cache

# Enabled Helm Hub
HELM_HUB_ENABLED=false
# Enabled Artifact Hub
# ARTIFACT_HUB_ENABLED=false
Loading

0 comments on commit e795104

Please sign in to comment.