Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into laverya/getGitOpsRepo
Browse files Browse the repository at this point in the history
  • Loading branch information
laverya committed Aug 24, 2020
2 parents ee05577 + cd02c68 commit e69e61f
Show file tree
Hide file tree
Showing 42 changed files with 376 additions and 917 deletions.
143 changes: 0 additions & 143 deletions kotsadm/api/src/cluster/cluster_store.ts
Expand Up @@ -10,110 +10,6 @@ import _ from "lodash";
export class ClusterStore {
constructor(private readonly pool: pg.Pool, private readonly params: Params) {}

async createOrUpdateHelmApplication(clusterId: string, helmApplication: any): Promise<void> {
const id = randomstring.generate({ capitalization: "lowercase" });

const q = `select id from helm_chart where cluster_id = $1 and helm_name = $2`;
const v = [
clusterId,
helmApplication.name,
]

const result = await this.pool.query(q, v);
if (result.rowCount === 0) {
return this.createHelmApplication(clusterId, helmApplication);
} else {
return this.updateHelmApplication(result.rows[0].id, helmApplication);
}
}

async createHelmApplication(clusterId: string, helmApplication: any): Promise<void> {
const id = randomstring.generate({ capitalization: "lowercase" });

let q = `insert into helm_chart (id, cluster_id, helm_name, namespace, version, first_deployed_at, last_deployed_at, is_deleted, chart_version, app_version)
values ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)`;
let v = [
id,
clusterId,
helmApplication.name,
helmApplication.namespace,
helmApplication.version,
helmApplication.firstDeployedAt,
helmApplication.lastDeployedAt,
helmApplication.isDeleted,
helmApplication.chartVersion,
helmApplication.appVersion,
]

await this.pool.query(q, v);

for (const source of helmApplication.sources) {
q = `insert into helm_chart_source (helm_chart_id, source) values ($1, $2)`;
v = [
id,
source,
];

await this.pool.query(q, v);
}
}

async updateHelmApplication(id: string, helmApplication: any): Promise<void> {
let q = `update helm_chart set
namespace = $1,
version = $2,
first_deployed_at = $3,
last_deployed_at = $4,
is_deleted = $5,
chart_version = $6,
app_version = $7
where id = $8`;
let v = [
helmApplication.namespace,
helmApplication.version,
helmApplication.firstDeployedAt,
helmApplication.lastDeployedAt,
helmApplication.isDeleted,
helmApplication.chartVersion,
helmApplication.appVersion,
id,
]

await this.pool.query(q, v);

q = `delete from helm_chart_source where helm_chart_id = $1`;
v = [id];
await this.pool.query(q, v);

for (const source of helmApplication.sources) {
q = `insert into helm_chart_source (helm_chart_id, source) values ($1, $2)`;
v = [
id,
source,
];

await this.pool.query(q, v);
}
}

async listClustersForGitHubRepo(owner: string, repo: string): Promise<Cluster[]> {
const q = `select cluster_id from cluster_github where owner = $1 and repo = $2`;
const v = [
owner,
repo,
];

const result = await this.pool.query(q, v);
const clusterIds = result.rows.map(row => row.cluster_id);

const clusters: Cluster[] = [];
for (const clusterId of clusterIds) {
clusters.push(await this.getGitOpsCluster(clusterId));
}

return clusters;
}

async getFromDeployToken(token: string): Promise<Cluster> {
const q = `select id from cluster where token = $1`;
const v = [
Expand Down Expand Up @@ -451,45 +347,6 @@ WHERE installation_id = $1 AND owner = $2 AND repo = $3 AND is_404 = TRUE`;
}
}

async getOperatorInstallationManifests(clusterId: string): Promise<string> {
const cluster = await this.getShipOpsCluster(clusterId);

const manifests = `apiVersion: apps/v1
kind: Deployment
metadata:
name: kotsadm-operator
spec:
selector:
matchLabels:
app: kotsadm-operator
template:
metadata:
labels:
app: kotsadm-operator
spec:
containers:
- env:
- name: KOTSADM_API_ENDPOINT
value: ${this.params.shipApiEndpoint}
- name: KOTSADM_TOKEN
value: ${cluster.shipOpsRef!.token}
image: kotsadm-operator
imagePullPolicy: Always
name: kotsadm-operator
resources:
limits:
cpu: 200m
memory: 1000Mi
requests:
cpu: 100m
memory: 500Mi
restartPolicy: Always
`;

return manifests;
}

async updateCluster(userId: string, clusterId: string, clusterName: string): Promise<boolean> {
const slugProposal = `${slugify(clusterName, { lower: true })}`;
const clusters = await this.listClusters(userId);
Expand Down
33 changes: 0 additions & 33 deletions kotsadm/api/src/controllers/kots/AppStatusAPI.ts

This file was deleted.

42 changes: 0 additions & 42 deletions kotsadm/api/src/controllers/kots/CurrentAPI.ts

This file was deleted.

119 changes: 0 additions & 119 deletions kotsadm/api/src/controllers/kots/DeployAPI.ts

This file was deleted.

26 changes: 0 additions & 26 deletions kotsadm/api/src/controllers/kots/InstallAPI.ts

This file was deleted.

14 changes: 0 additions & 14 deletions kotsadm/api/src/kots_app/kots_app_status_store.ts
Expand Up @@ -26,18 +26,4 @@ export class KotsAppStatusStore {

return kotsAppStatus;
}

async setKotsAppStatus(appId: string, resourceStates: any, updatedAt: Date): Promise<void> {
const q = `
insert into app_status (app_id, resource_states, updated_at) values ($1, $2, $3)
on conflict (app_id) do update set resource_states = $2, updated_at = $3
`;
const v = [
appId,
JSON.stringify(resourceStates),
updatedAt,
];

await this.pool.query(q, v);
}
}

0 comments on commit e69e61f

Please sign in to comment.