All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.arquillian.cube.kubernetes.impl.label.DefaultLabelProvider Maven / Gradle / Ivy

The newest version!
package org.arquillian.cube.kubernetes.impl.label;

import io.fabric8.kubernetes.clnt.v4_0.KubernetesClient;
import java.util.HashMap;
import java.util.Map;
import org.arquillian.cube.kubernetes.api.LabelProvider;
import org.jboss.arquillian.core.api.Instance;
import org.jboss.arquillian.core.api.annotation.Inject;
import org.jboss.arquillian.core.spi.Validate;

public class DefaultLabelProvider implements LabelProvider {

    @Inject
    Instance client;

    private LabelProvider delegate;

    @Override
    public Map getLabels() {
        return delegate.getLabels();
    }

    @Override
    public LabelProvider toImmutable() {
        if (delegate != null) {
            return delegate;
        }
        synchronized (this) {
            if (delegate == null) {
                delegate = new ImmutableLabelProvider(client.get());
            }
        }
        return delegate;
    }

    public static class ImmutableLabelProvider implements LabelProvider {

        private final KubernetesClient client;

        private ImmutableLabelProvider(KubernetesClient client) {
            Validate.notNull(client, "A KubernetesClient instance is required.");
            this.client = client;
        }

        @Override
        public Map getLabels() {
            Map labels = new HashMap();
            labels.put("project", client.getNamespace());
            labels.put("framework", "arquillian");
            labels.put("component", "integrationTest");
            return labels;
        }

        @Override
        public LabelProvider toImmutable() {
            return this;
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy