Skip to content

Commit

Permalink
Merge branch 'release/1.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
clivebor committed Dec 6, 2022
2 parents b443847 + beedbce commit c57b412
Show file tree
Hide file tree
Showing 98 changed files with 6,341 additions and 3,967 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,8 @@ Think Helm, Git, GitOps, Continuous Deployment using ArgoCD awesomeness, all don
- [Additional cluster setup](./docs/add-cluster.md)
- [Users and Roles](./docs/users_roles.md)
- [Notes](./docs/notes.md)

## Development

- [Running Ahoy](./docs/running.md)
- [DB migration](./docs/db-migration.md)
6 changes: 3 additions & 3 deletions ahoy-components/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<parent>
<groupId>za.co.lsd.ahoy</groupId>
<artifactId>ahoy</artifactId>
<version>0.17.0</version>
<version>1.0.0</version>
</parent>
<artifactId>ahoy-components</artifactId>

Expand Down Expand Up @@ -82,7 +82,7 @@

<dependency>
<groupId>io.fabric8</groupId>
<artifactId>openshift-client</artifactId>
<artifactId>kubernetes-client</artifactId>
<version>4.13.3</version>
</dependency>
<dependency>
Expand Down Expand Up @@ -112,7 +112,7 @@
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
<version>1.9</version>
<version>1.10.0</version>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public class AhoyServerProperties {
private String releaseName = "ahoy";
private String releaseNamespace = "ahoy";
private String host = "default.host";
private String clusterType = "kubernetes";
private String repoPath;
private Auth auth;
private SealedSecrets sealedSecrets = new SealedSecrets();
Expand All @@ -46,6 +45,7 @@ public static class Auth {
private String clientId;
private String issuer;
private String jwkSetUri;
private String accountUri;
}

@Data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ public String resolve(EnvironmentRelease environmentRelease) {
Environment environment = environmentRelease.getEnvironment();
Cluster cluster = environment.getCluster();
Release release = environmentRelease.getRelease();
return StringUtils.truncate(cluster.getName() + "-" + environment.getName() + "-" + release.getName(), 53);
return StringUtils.truncate(cluster.getName() + "-" + environment.getKey() + "-" + release.getName(), 53);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import lombok.Setter;
import lombok.ToString;
import org.hibernate.Hibernate;
import org.hibernate.annotations.Type;
import za.co.lsd.ahoy.server.environments.Environment;

import javax.persistence.*;
Expand Down Expand Up @@ -53,53 +52,25 @@ public class Cluster {
@JsonProperty(access = WRITE_ONLY)
private String masterUrl;
@NotNull
@Lob
@Type(type = "org.hibernate.type.TextType")
@JsonProperty(access = WRITE_ONLY)
@ToString.Exclude
private String token;
@NotNull
@Lob
@Type(type = "org.hibernate.type.TextType")
@JsonProperty(access = WRITE_ONLY)
@ToString.Exclude
private String caCertData;
@NotNull
private String host;
@NotNull
private boolean inCluster;
@NotNull
@Enumerated(EnumType.STRING)
private ClusterType type;

@OneToMany(mappedBy = "cluster", cascade = CascadeType.REMOVE)
@OrderBy("id")
@JsonIgnore
@ToString.Exclude
private List<Environment> environments = new ArrayList<>();

public Cluster(@NotNull String name, @NotNull String masterUrl, @NotNull ClusterType type) {
public Cluster(@NotNull String name, @NotNull String masterUrl) {
this.name = name;
this.masterUrl = masterUrl;
this.type = type;
}

public Cluster(Long id, @NotNull String name, @NotNull String masterUrl, @NotNull ClusterType type) {
public Cluster(Long id, @NotNull String name, @NotNull String masterUrl) {
this.id = id;
this.name = name;
this.masterUrl = masterUrl;
this.type = type;
}

public Cluster(ClusterDTO dto) {
this.id = dto.getId();
this.name = dto.getName();
this.masterUrl = dto.getMasterUrl();
this.token = dto.getToken();
this.caCertData = dto.getCaCertData();
this.host = dto.getHost();
this.inCluster = dto.isInCluster();
this.type = dto.getType();
}

public void addEnvironment(Environment environment) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,7 @@ public interface ClusterFullProjection {

String getMasterUrl();

String getToken();

String getCaCertData();

String getHost();

boolean getInCluster();

ClusterType getType();
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
import org.springframework.data.rest.webmvc.ResourceNotFoundException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import za.co.lsd.ahoy.server.clustermanager.ClusterManager;
import za.co.lsd.ahoy.server.clustermanager.ClusterManagerFactory;
import za.co.lsd.ahoy.server.environments.Environment;
import za.co.lsd.ahoy.server.environments.EnvironmentService;

Expand All @@ -30,12 +28,10 @@
public class ClusterService {
private final ClusterRepository clusterRepository;
private final EnvironmentService environmentService;
private final ClusterManagerFactory clusterManagerFactory;

public ClusterService(ClusterRepository clusterRepository, EnvironmentService environmentService, ClusterManagerFactory clusterManagerFactory) {
public ClusterService(ClusterRepository clusterRepository, EnvironmentService environmentService) {
this.clusterRepository = clusterRepository;
this.environmentService = environmentService;
this.clusterManagerFactory = clusterManagerFactory;
}

public Long count() {
Expand All @@ -56,9 +52,4 @@ public Cluster delete(Long clusterId) {

return cluster;
}

public void testConnection(Cluster cluster) {
ClusterManager clusterManager = clusterManagerFactory.newManager(cluster);
clusterManager.testConnection();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,4 @@ public interface ClusterSimpleProjection {
String getHost();

boolean getInCluster();

ClusterType getType();
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,5 @@ public interface ClusterSummaryProjection {

boolean getInCluster();

ClusterType getType();

List<EnvironmentSimpleProjection> getEnvironments();
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.annotation.Secured;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import za.co.lsd.ahoy.server.security.Role;

@RepositoryRestController
Expand All @@ -48,10 +51,4 @@ public ResponseEntity<Cluster> delete(@PathVariable Long clusterId) {

return new ResponseEntity<>(cluster, new HttpHeaders(), HttpStatus.OK);
}

@PostMapping("/test")
@ResponseStatus(value = HttpStatus.OK)
public void test(@RequestBody ClusterDTO clusterDTO) {
clusterService.testConnection(new Cluster(clusterDTO));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,12 @@
package za.co.lsd.ahoy.server.cluster;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.BeanInitializationException;
import org.springframework.stereotype.Component;
import za.co.lsd.ahoy.server.AhoyServerProperties;
import za.co.lsd.ahoy.server.security.AuthUtility;
import za.co.lsd.ahoy.server.security.Role;

import javax.annotation.PostConstruct;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

@Component
@Slf4j
Expand All @@ -43,32 +38,14 @@ public InitDefaultCluster(AhoyServerProperties serverProperties, ClusterReposito
@PostConstruct
public void init() {
AuthUtility.runAs(Role.admin, () -> {
try {
if (clusterRepository.count() == 0) {
log.info("Detected no clusters setup, initializing default cluster..");

Path token = Paths.get("/var/run/secrets/kubernetes.io/serviceaccount/token");
Path caCrt = Paths.get("/var/run/secrets/kubernetes.io/serviceaccount/ca.crt");

if (Files.exists(token) && Files.exists(caCrt)) {
log.info("Found token and ca.crt files");

ClusterType clusterType = ClusterType.KUBERNETES;
if ("openshift".equals(serverProperties.getClusterType())) {
clusterType = ClusterType.OPENSHIFT;
}

Cluster cluster = new Cluster("in-cluster", "https://kubernetes.default.svc", clusterType);
cluster.setHost(serverProperties.getHost());
cluster.setToken(Files.readString(token));
cluster.setCaCertData(Files.readString(caCrt));
cluster.setInCluster(true);
log.info("Saving default cluster: {}", cluster);
clusterRepository.save(cluster);
}
}
} catch (IOException e) {
throw new BeanInitializationException("Failed to read token or CA cert whilst initializing default cluster");
if (clusterRepository.count() == 0) {
log.info("Detected no clusters setup, initializing default cluster..");

Cluster cluster = new Cluster("in-cluster", "https://kubernetes.default.svc");
cluster.setHost(serverProperties.getHost());
cluster.setInCluster(true);
log.info("Saving default cluster: {}", cluster);
clusterRepository.save(cluster);
}
});
}
Expand Down

This file was deleted.

This file was deleted.

Loading

0 comments on commit c57b412

Please sign in to comment.