Search in sources :

Example 1 with Good

use of io.fabric8.kubernetes.client.Good in project java-operator-sdk by java-operator-sdk.

the class WebPageOperator method main.

public static void main(String[] args) throws IOException {
    log.info("WebServer Operator starting!");
    Config config = new ConfigBuilder().withNamespace(null).build();
    KubernetesClient client = new DefaultKubernetesClient(config);
    Operator operator = new Operator(client, DefaultConfigurationService.instance());
    operator.register(new WebPageReconciler(client));
    operator.installShutdownHook();
    operator.start();
    new FtBasic(new TkFork(new FkRegex("/health", "ALL GOOD!")), 8080).start(Exit.NEVER);
}
Also used : Operator(io.javaoperatorsdk.operator.Operator) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) TkFork(org.takes.facets.fork.TkFork) Config(io.fabric8.kubernetes.client.Config) FtBasic(org.takes.http.FtBasic) ConfigBuilder(io.fabric8.kubernetes.client.ConfigBuilder) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) FkRegex(org.takes.facets.fork.FkRegex)

Example 2 with Good

use of io.fabric8.kubernetes.client.Good in project java-operator-sdk by java-operator-sdk.

the class MySQLSchemaOperator method main.

public static void main(String[] args) throws IOException {
    log.info("MySQL Schema Operator starting");
    Config config = new ConfigBuilder().withNamespace(null).build();
    KubernetesClient client = new DefaultKubernetesClient(config);
    Operator operator = new Operator(client, new ConfigurationServiceOverrider(DefaultConfigurationService.instance()).withMetrics(new MicrometerMetrics(new LoggingMeterRegistry())).build());
    operator.register(new MySQLSchemaReconciler(client, MySQLDbConfig.loadFromEnvironmentVars()));
    operator.installShutdownHook();
    operator.start();
    new FtBasic(new TkFork(new FkRegex("/health", "ALL GOOD!")), 8080).start(Exit.NEVER);
}
Also used : Operator(io.javaoperatorsdk.operator.Operator) LoggingMeterRegistry(io.micrometer.core.instrument.logging.LoggingMeterRegistry) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) ConfigurationServiceOverrider(io.javaoperatorsdk.operator.api.config.ConfigurationServiceOverrider) TkFork(org.takes.facets.fork.TkFork) Config(io.fabric8.kubernetes.client.Config) FtBasic(org.takes.http.FtBasic) ConfigBuilder(io.fabric8.kubernetes.client.ConfigBuilder) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) MicrometerMetrics(io.javaoperatorsdk.operator.monitoring.micrometer.MicrometerMetrics) FkRegex(org.takes.facets.fork.FkRegex)

Example 3 with Good

use of io.fabric8.kubernetes.client.Good in project stackgres by ongres.

the class ClusterEventResourceTest method ifEventsAreCreated_itShouldReturnThenInAnArray.

@Test
void ifEventsAreCreated_itShouldReturnThenInAnArray() {
    try (KubernetesClient client = factory.create()) {
        client.v1().events().inNamespace("test-namespace").create(new EventBuilder().withNewMetadata().withNamespace("test-namespace").withName("test.1").endMetadata().withType("Normal").withMessage("Test").withLastTimestamp(DateTimeFormatter.ISO_INSTANT.format(Instant.ofEpochMilli(1))).withInvolvedObject(new ObjectReferenceBuilder().withKind(StackGresCluster.KIND).withNamespace("test-namespace").withName("test").withUid("1").build()).build());
        client.v1().events().inNamespace("test-namespace").create(new EventBuilder().withNewMetadata().withNamespace("test-namespace").withName("test.2").endMetadata().withType("Normal").withMessage("All good!").withLastTimestamp(DateTimeFormatter.ISO_INSTANT.format(Instant.ofEpochMilli(2))).withInvolvedObject(new ObjectReferenceBuilder().withKind("StatefulSet").withNamespace("test-namespace").withName("test").withUid("1").build()).build());
        client.v1().events().inNamespace("test-namespace").create(new EventBuilder().withNewMetadata().withNamespace("test-namespace").withName("test.3").endMetadata().withType("Warning").withMessage("Something wrong :(").withLastTimestamp(DateTimeFormatter.ISO_INSTANT.format(Instant.ofEpochMilli(3))).withInvolvedObject(new ObjectReferenceBuilder().withKind("Pod").withNamespace("test-namespace").withName("test-0").withUid("1").build()).build());
        client.v1().events().inNamespace("test-namespace").create(new EventBuilder().withNewMetadata().withNamespace("test-namespace").withName("test.4").endMetadata().withType("Normal").withMessage("I am here too").withLastTimestamp(DateTimeFormatter.ISO_INSTANT.format(Instant.ofEpochMilli(0))).withInvolvedObject(new ObjectReferenceBuilder().withKind(StackGresDbOps.KIND).withNamespace("test-namespace").withName("test-operation").withUid("1").build()).build());
    }
    given().when().header(AUTHENTICATION_HEADER).get("/stackgres/namespaces/test-namespace/sgclusters/test/events").then().statusCode(200).body("", Matchers.hasSize(4)).body("[0].metadata.name", Matchers.equalTo("test.4")).body("[0].type", Matchers.equalTo("Normal")).body("[0].message", Matchers.equalTo("I am here too")).body("[1].metadata.name", Matchers.equalTo("test.1")).body("[1].type", Matchers.equalTo("Normal")).body("[1].message", Matchers.equalTo("Test")).body("[2].metadata.name", Matchers.equalTo("test.2")).body("[2].type", Matchers.equalTo("Normal")).body("[2].message", Matchers.equalTo("All good!")).body("[3].metadata.name", Matchers.equalTo("test.3")).body("[3].type", Matchers.equalTo("Warning")).body("[3].message", Matchers.equalTo("Something wrong :("));
}
Also used : KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) EventBuilder(io.fabric8.kubernetes.api.model.EventBuilder) ObjectReferenceBuilder(io.fabric8.kubernetes.api.model.ObjectReferenceBuilder) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Example 4 with Good

use of io.fabric8.kubernetes.client.Good in project docker-maven-plugin by fabric8io.

the class DockerAssemblyManager method verifyGivenDockerfile.

// visible for testing
void verifyGivenDockerfile(File dockerFile, BuildImageConfiguration buildConfig, FixedStringSearchInterpolator interpolator, Logger log) throws IOException {
    AssemblyConfiguration assemblyConfig = buildConfig.getAssemblyConfiguration();
    if (assemblyConfig == null) {
        return;
    }
    String name = assemblyConfig.getName();
    for (String keyword : new String[] { "ADD", "COPY" }) {
        List<String[]> lines = DockerFileUtil.extractLines(dockerFile, keyword, interpolator);
        for (String[] line : lines) {
            if (!line[0].startsWith("#")) {
                // Skip command flags like --chown
                int i;
                for (i = 1; i < line.length; i++) {
                    String component = line[i];
                    if (!component.startsWith("--")) {
                        break;
                    }
                }
                // contains an ADD/COPY ... targetDir .... All good.
                if (i < line.length && line[i].contains(name)) {
                    return;
                }
            }
        }
    }
    log.warn("Dockerfile %s does not contain an ADD or COPY directive to include assembly created at %s. Ignoring assembly.", dockerFile.getPath(), name);
}
Also used : AssemblyConfiguration(io.fabric8.maven.docker.config.AssemblyConfiguration)

Example 5 with Good

use of io.fabric8.kubernetes.client.Good in project fabric8 by jboss-fuse.

the class HealthCheck method healthList.

@Override
public List<HealthStatus> healthList() {
    List<HealthStatus> answer = new ArrayList<HealthStatus>();
    FabricStatus status = fabricService.getFabricStatus();
    Collection<ProfileStatus> statuses = status.getProfileStatusMap().values();
    for (ProfileStatus profile : statuses) {
        String id = profile.getProfile();
        int instances = profile.getCount();
        Integer minimum = profile.getMinimumInstances();
        Integer maximum = profile.getMaximumInstances();
        double healthPercent = profile.getHealth(instances);
        String level = "INFO";
        String message = "Profile " + id + " has health " + percentInstance.format(healthPercent);
        if (minimum != null) {
            if (instances <= 0) {
                level = "ERROR";
                message = "Profile " + id + " has no instances running! Should have at least " + minimum;
            } else if (instances < minimum) {
                level = "WARNING";
                message = "Profile " + id + " needs more instances running. Should have at least " + minimum + " but currently has only " + instances;
            }
        }
        if (maximum != null && level.equals("INFO") && instances > maximum) {
            level = "WARNING";
            message = "Profile " + id + " has too many instances running. Should have at most " + maximum + " but currently has only " + instances;
        }
        answer.add(new HealthStatus("io.fabric8.profileHealth", id, level, message, instances, minimum, maximum, healthPercent));
    }
    String worries = "";
    for (HealthStatus hs : answer) {
        if ("WARNING".equals(hs.getLevel()) || "ERROR".equals(hs.getLevel())) {
            worries += hs + " , ";
        }
    }
    if ("".equals(worries)) {
        this.currentStatus = "Good";
    } else {
        this.currentStatus = "Getting Worried {" + worries + " }";
    }
    return answer;
}
Also used : HealthStatus(io.fabric8.api.jmx.HealthStatus) ArrayList(java.util.ArrayList) ProfileStatus(io.fabric8.api.ProfileStatus) FabricStatus(io.fabric8.api.FabricStatus)

Aggregations

KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)6 Config (io.fabric8.kubernetes.client.Config)4 DefaultKubernetesClient (io.fabric8.kubernetes.client.DefaultKubernetesClient)4 ConfigBuilder (io.fabric8.kubernetes.client.ConfigBuilder)3 Operator (io.javaoperatorsdk.operator.Operator)3 Test (org.junit.jupiter.api.Test)3 EventBuilder (io.fabric8.kubernetes.api.model.EventBuilder)2 ObjectReferenceBuilder (io.fabric8.kubernetes.api.model.ObjectReferenceBuilder)2 IOException (java.io.IOException)2 FkRegex (org.takes.facets.fork.FkRegex)2 TkFork (org.takes.facets.fork.TkFork)2 FtBasic (org.takes.http.FtBasic)2 KubernetesConfigParser (com.netflix.spinnaker.clouddriver.kubernetes.v1.security.KubernetesConfigParser)1 DeploymentConfiguration (com.netflix.spinnaker.halyard.config.model.v1.node.DeploymentConfiguration)1 Node (com.netflix.spinnaker.halyard.config.model.v1.node.Node)1 Provider (com.netflix.spinnaker.halyard.config.model.v1.node.Provider)1 Validator (com.netflix.spinnaker.halyard.config.model.v1.node.Validator)1 DockerRegistryReference (com.netflix.spinnaker.halyard.config.model.v1.providers.containers.DockerRegistryReference)1 KubernetesAccount (com.netflix.spinnaker.halyard.config.model.v1.providers.kubernetes.KubernetesAccount)1 ConfigProblemBuilder (com.netflix.spinnaker.halyard.config.problem.v1.ConfigProblemBuilder)1