Search in sources :

Example 1 with RemoveAnnotationDecorator

use of io.dekorate.kubernetes.decorator.RemoveAnnotationDecorator in project dekorate by dekorateio.

the class OpenshiftManifestGenerator method addDecorators.

protected void addDecorators(String group, OpenshiftConfig config, ImageConfiguration imageConfig) {
    super.addDecorators(group, config);
    if (config.getReplicas() != 1) {
        resourceRegistry.decorate(group, new ApplyReplicasDecorator(config.getName(), config.getReplicas()));
    }
    resourceRegistry.decorate(group, new ApplyDeploymentTriggerDecorator(config.getName(), imageConfig.getName() + ":" + imageConfig.getVersion()));
    resourceRegistry.decorate(group, new AddRouteDecorator(config));
    if (config.hasAttribute(RUNTIME_TYPE)) {
        resourceRegistry.decorate(group, new AddLabelDecorator(config.getName(), new Label(OpenshiftLabels.RUNTIME, config.getAttribute(RUNTIME_TYPE), new String[0])));
    }
    resourceRegistry.decorate(group, new RemoveAnnotationDecorator(config.getName(), Annotations.VCS_URL));
    Project project = getProject();
    Optional<VcsConfig> vcsConfig = configurationRegistry.get(VcsConfig.class);
    String remote = vcsConfig.map(VcsConfig::getRemote).orElse(Git.ORIGIN);
    boolean httpsPrefered = vcsConfig.map(VcsConfig::isHttpsPreferred).orElse(false);
    String vcsUrl = project.getScmInfo() != null && Strings.isNotNullOrEmpty(project.getScmInfo().getRemote().get(Git.ORIGIN)) ? Git.getRemoteUrl(project.getRoot(), remote, httpsPrefered).orElse(Labels.UNKNOWN) : Labels.UNKNOWN;
    resourceRegistry.decorate(group, new AddVcsUrlAnnotationDecorator(config.getName(), OpenshiftAnnotations.VCS_URL, vcsUrl));
    resourceRegistry.decorate(group, new AddCommitIdAnnotationDecorator());
}
Also used : RemoveAnnotationDecorator(io.dekorate.kubernetes.decorator.RemoveAnnotationDecorator) Label(io.dekorate.kubernetes.config.Label) AddVcsUrlAnnotationDecorator(io.dekorate.kubernetes.decorator.AddVcsUrlAnnotationDecorator) VcsConfig(io.dekorate.option.config.VcsConfig) AddRouteDecorator(io.dekorate.openshift.decorator.AddRouteDecorator) WithProject(io.dekorate.WithProject) Project(io.dekorate.project.Project) AddCommitIdAnnotationDecorator(io.dekorate.kubernetes.decorator.AddCommitIdAnnotationDecorator) ApplyDeploymentTriggerDecorator(io.dekorate.openshift.decorator.ApplyDeploymentTriggerDecorator) AddLabelDecorator(io.dekorate.kubernetes.decorator.AddLabelDecorator) ApplyReplicasDecorator(io.dekorate.openshift.decorator.ApplyReplicasDecorator)

Example 2 with RemoveAnnotationDecorator

use of io.dekorate.kubernetes.decorator.RemoveAnnotationDecorator in project quarkus by quarkusio.

the class KubernetesCommonHelper method createAnnotationDecorators.

private static List<DecoratorBuildItem> createAnnotationDecorators(Optional<Project> project, String target, String name, PlatformConfiguration config, Optional<MetricsCapabilityBuildItem> metricsConfiguration, List<KubernetesPortBuildItem> ports) {
    List<DecoratorBuildItem> result = new ArrayList<>();
    ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC);
    project.ifPresent(p -> {
        ScmInfo scm = p.getScmInfo();
        String vcsUrl = scm != null ? scm.getRemote().get("origin") : null;
        String commitId = scm != null ? scm.getCommit() : null;
        // Dekorate uses its own annotations. Let's replace them with the quarkus ones.
        result.add(new DecoratorBuildItem(target, new RemoveAnnotationDecorator(Annotations.VCS_URL)));
        result.add(new DecoratorBuildItem(target, new RemoveAnnotationDecorator(Annotations.COMMIT_ID)));
        // Add quarkus vcs annotations
        if (commitId != null) {
            result.add(new DecoratorBuildItem(target, new AddAnnotationDecorator(name, new Annotation(QUARKUS_ANNOTATIONS_COMMIT_ID, commitId, new String[0]))));
        }
        if (vcsUrl != null) {
            result.add(new DecoratorBuildItem(target, new AddAnnotationDecorator(name, new Annotation(QUARKUS_ANNOTATIONS_VCS_URL, vcsUrl, new String[0]))));
        }
    });
    if (config.isAddBuildTimestamp()) {
        result.add(new DecoratorBuildItem(target, new AddAnnotationDecorator(name, new Annotation(QUARKUS_ANNOTATIONS_BUILD_TIMESTAMP, now.format(DateTimeFormatter.ofPattern("yyyy-MM-dd - HH:mm:ss Z")), new String[0]))));
    }
    if (config.getExposition().isPresent() && config.getExposition().get().expose) {
        Map<String, String> expostionAnnotations = config.getExposition().get().annotations;
        String kind = "Ingress";
        if (config.getTargetPlatformName().equals(OPENSHIFT)) {
            kind = "Route";
        }
        for (Map.Entry<String, String> annotation : expostionAnnotations.entrySet()) {
            result.add(new DecoratorBuildItem(target, new AddAnnotationDecorator(name, annotation.getKey(), annotation.getValue(), kind)));
        }
    }
    if (config.getPrometheusConfig().annotations) {
        // Add metrics annotations
        metricsConfiguration.ifPresent(m -> {
            String path = m.metricsEndpoint();
            String prefix = config.getPrometheusConfig().prefix;
            if (!ports.isEmpty() && path != null) {
                result.add(new DecoratorBuildItem(target, new AddAnnotationDecorator(name, config.getPrometheusConfig().scrape.orElse(prefix + "/scrape"), "true", PROMETHEUS_ANNOTATION_TARGETS)));
                result.add(new DecoratorBuildItem(target, new AddAnnotationDecorator(name, config.getPrometheusConfig().path.orElse(prefix + "/path"), path, PROMETHEUS_ANNOTATION_TARGETS)));
                result.add(new DecoratorBuildItem(target, new AddAnnotationDecorator(name, config.getPrometheusConfig().port.orElse(prefix + "/port"), "" + ports.get(0).getPort(), PROMETHEUS_ANNOTATION_TARGETS)));
                result.add(new DecoratorBuildItem(target, new AddAnnotationDecorator(name, config.getPrometheusConfig().scheme.orElse(prefix + "/scheme"), "http", PROMETHEUS_ANNOTATION_TARGETS)));
            }
        });
    }
    // Add metrics annotations
    return result;
}
Also used : DecoratorBuildItem(io.quarkus.kubernetes.spi.DecoratorBuildItem) AddAnnotationDecorator(io.dekorate.kubernetes.decorator.AddAnnotationDecorator) ZonedDateTime(java.time.ZonedDateTime) RemoveAnnotationDecorator(io.dekorate.kubernetes.decorator.RemoveAnnotationDecorator) ArrayList(java.util.ArrayList) ScmInfo(io.dekorate.project.ScmInfo) Map(java.util.Map) HashMap(java.util.HashMap) Annotation(io.dekorate.kubernetes.config.Annotation)

Aggregations

RemoveAnnotationDecorator (io.dekorate.kubernetes.decorator.RemoveAnnotationDecorator)2 WithProject (io.dekorate.WithProject)1 Annotation (io.dekorate.kubernetes.config.Annotation)1 Label (io.dekorate.kubernetes.config.Label)1 AddAnnotationDecorator (io.dekorate.kubernetes.decorator.AddAnnotationDecorator)1 AddCommitIdAnnotationDecorator (io.dekorate.kubernetes.decorator.AddCommitIdAnnotationDecorator)1 AddLabelDecorator (io.dekorate.kubernetes.decorator.AddLabelDecorator)1 AddVcsUrlAnnotationDecorator (io.dekorate.kubernetes.decorator.AddVcsUrlAnnotationDecorator)1 AddRouteDecorator (io.dekorate.openshift.decorator.AddRouteDecorator)1 ApplyDeploymentTriggerDecorator (io.dekorate.openshift.decorator.ApplyDeploymentTriggerDecorator)1 ApplyReplicasDecorator (io.dekorate.openshift.decorator.ApplyReplicasDecorator)1 VcsConfig (io.dekorate.option.config.VcsConfig)1 Project (io.dekorate.project.Project)1 ScmInfo (io.dekorate.project.ScmInfo)1 DecoratorBuildItem (io.quarkus.kubernetes.spi.DecoratorBuildItem)1 ZonedDateTime (java.time.ZonedDateTime)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1