Java Code Examples for io.fabric8.kubernetes.api.model.ObjectMeta#setName()

The following examples show how to use io.fabric8.kubernetes.api.model.ObjectMeta#setName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MockKubernetesServerSupport.java    From kogito-runtimes with Apache License 2.0 6 votes vote down vote up
protected void createMockService(final String serviceName, final String ip, final Map<String, String> labels, final String namespace) {
    final ServiceSpec serviceSpec = new ServiceSpec();
    serviceSpec.setPorts(Collections.singletonList(new ServicePort("http", 0, 8080, "http", new IntOrString(8080))));
    serviceSpec.setClusterIP(ip);
    serviceSpec.setType("ClusterIP");
    serviceSpec.setSessionAffinity("ClientIP");

    final ObjectMeta metadata = new ObjectMeta();
    metadata.setName(serviceName);
    metadata.setNamespace(MOCK_NAMESPACE);
    metadata.setLabels(labels);

    final Service service = new Service("v1", "Service", metadata, serviceSpec, new ServiceStatus(new LoadBalancerStatus()));
    if (namespace != null) {
        this.server.getClient().inNamespace(namespace).services().create(service);
    } else {
        this.server.getClient().services().create(service);
    }

}
 
Example 2
Source File: StorageClassIT.java    From kubernetes-client with Apache License 2.0 6 votes vote down vote up
@Before
public void init() {
  ObjectMeta metadata = new ObjectMeta();
  metadata.setName(name);

  Map<String, String> parameters = new HashMap<>();
  parameters.put("key", "value1");

  storageClass = new StorageClassBuilder().withApiVersion("storage.k8s.io/v1")
    .withKind("StorageClass")
    .withMetadata(metadata)
    .withParameters(parameters)
    .withProvisioner("k8s.io/minikube-hostpath")
    .build();

  client.storage().storageClasses().createOrReplace(storageClass);
}
 
Example 3
Source File: KubernetesDiscoveryClientFilterTest.java    From spring-cloud-kubernetes with Apache License 2.0 6 votes vote down vote up
@Test
public void testFilteredServices() {
	List<String> springBootServiceNames = Arrays.asList("serviceA", "serviceB");
	List<Service> services = createSpringBootServiceByName(springBootServiceNames);

	// Add non spring boot service
	Service service = new Service();
	ObjectMeta objectMeta = new ObjectMeta();
	objectMeta.setName("ServiceNonSpringBoot");
	service.setMetadata(objectMeta);
	services.add(service);

	ServiceList serviceList = new ServiceList();
	serviceList.setItems(services);
	when(this.serviceOperation.list()).thenReturn(serviceList);
	when(this.kubernetesClient.services()).thenReturn(this.serviceOperation);

	when(this.properties.getFilter())
			.thenReturn("metadata.additionalProperties['spring-boot']");

	List<String> filteredServices = this.underTest.getServices();

	System.out.println("Filtered Services: " + filteredServices);
	assertThat(filteredServices).isEqualTo(springBootServiceNames);

}
 
Example 4
Source File: K8sPodManagerTest.java    From onos with Apache License 2.0 6 votes vote down vote up
private static Pod createK8sPod(String uid, String name) {
    ObjectMeta meta = new ObjectMeta();
    meta.setUid(uid);
    meta.setName(name);

    PodStatus status = new PodStatus();
    status.setPhase("Running");

    Pod pod = new Pod();
    pod.setApiVersion("v1");
    pod.setKind("pod");
    pod.setMetadata(meta);
    pod.setStatus(status);

    return pod;
}
 
Example 5
Source File: TillerInstaller.java    From microbean-helm with Apache License 2.0 5 votes vote down vote up
protected Secret createSecret(final String namespace,
                              final URI tlsKeyUri,
                              final URI tlsCertUri,
                              final URI tlsCaCertUri,
                              final Map<String, String> labels)
  throws IOException {
  
  final Secret secret = new Secret();
  secret.setType("Opaque");

  final Map<String, String> secretData = new HashMap<>();
  
  try (final InputStream tlsKeyStream = read(tlsKeyUri)) {
    if (tlsKeyStream != null) {
      secretData.put("tls.key", Base64.getEncoder().encodeToString(toByteArray(tlsKeyStream)));
    }
  }

  try (final InputStream tlsCertStream = read(tlsCertUri)) {
    if (tlsCertStream != null) {
      secretData.put("tls.crt", Base64.getEncoder().encodeToString(toByteArray(tlsCertStream)));
    }
  }
  
  try (final InputStream tlsCaCertStream = read(tlsCaCertUri)) {
    if (tlsCaCertStream != null) {
      secretData.put("ca.crt", Base64.getEncoder().encodeToString(toByteArray(tlsCaCertStream)));
    }
  }

  secret.setData(secretData);

  final ObjectMeta metadata = new ObjectMeta();
  metadata.setNamespace(normalizeNamespace(namespace));
  metadata.setName(SECRET_NAME);
  metadata.setLabels(normalizeLabels(labels));
  secret.setMetadata(metadata);
  
  return secret;
}
 
Example 6
Source File: DefaultContainerFactoryTests.java    From spring-cloud-deployer-kubernetes with Apache License 2.0 5 votes vote down vote up
private Secret randomSecret() {
	String secretName = "secret-" + UUID.randomUUID().toString().substring(0, 18);
	String secretValue = "dXNlcjpwYXNz"; // base64 encoded string of: user:pass

	ObjectMeta objectMeta = new ObjectMeta();
	objectMeta.setName(secretName);

	Secret secret = new Secret();
	secret.setData(Collections.singletonMap(ProbeCreator.PROBE_CREDENTIALS_SECRET_KEY_NAME, secretValue));
	secret.setMetadata(objectMeta);

	return secret;
}
 
Example 7
Source File: RoutesTest.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
private Service createService(String portString, int portInt) {
  Service service = new Service();
  ObjectMeta metadata = new ObjectMeta();
  metadata.setName("servicename");
  service.setMetadata(metadata);
  ServiceSpec spec = new ServiceSpec();
  spec.setPorts(
      Collections.singletonList(new ServicePort(portString, null, portInt, "TCP", null)));
  service.setSpec(spec);
  return service;
}
 
Example 8
Source File: K8sEndpointsManagerTest.java    From onos with Apache License 2.0 5 votes vote down vote up
private static Endpoints createK8sEndpoints(String uid, String name) {
    ObjectMeta meta = new ObjectMeta();
    meta.setUid(uid);
    meta.setName(name);

    Endpoints endpoints = new Endpoints();
    endpoints.setApiVersion("v1");
    endpoints.setKind("endpoints");
    endpoints.setMetadata(meta);

    return endpoints;
}
 
Example 9
Source File: OpenShiftPreviewUrlExposerTest.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void shouldProvisionRouteWhenNotFound() throws InternalInfrastructureException {
  final int PORT = 8080;
  final String SERVER_PORT_NAME = "server-" + PORT;
  final String SERVICE_NAME = "servicename";

  CommandImpl command =
      new CommandImpl("a", "a", "a", new PreviewUrlImpl(PORT, null), Collections.emptyMap());

  Service service = new Service();
  ObjectMeta serviceMeta = new ObjectMeta();
  serviceMeta.setName(SERVICE_NAME);
  service.setMetadata(serviceMeta);
  ServiceSpec serviceSpec = new ServiceSpec();
  serviceSpec.setPorts(
      singletonList(new ServicePort(SERVER_PORT_NAME, null, PORT, "TCP", new IntOrString(PORT))));
  service.setSpec(serviceSpec);

  Map<String, Service> services = new HashMap<>();
  services.put(SERVICE_NAME, service);

  OpenShiftEnvironment env =
      OpenShiftEnvironment.builder()
          .setCommands(singletonList(new CommandImpl(command)))
          .setServices(services)
          .setRoutes(new HashMap<>())
          .build();

  previewUrlEndpointsProvisioner.expose(env);
  assertEquals(env.getRoutes().size(), 1);
  Route provisionedRoute = env.getRoutes().values().iterator().next();
  assertEquals(provisionedRoute.getSpec().getTo().getName(), SERVICE_NAME);
  assertEquals(
      provisionedRoute.getSpec().getPort().getTargetPort().getStrVal(), SERVER_PORT_NAME);
}
 
Example 10
Source File: KubeCloudInstanceImplTest.java    From teamcity-kubernetes-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetStartedTime() throws Exception {
    KubeCloudImage image = m.mock(KubeCloudImage.class);
    ObjectMeta metadata = new ObjectMeta();
    metadata.setName("foo");
    Pod pod = new Pod("1.0", "kind", metadata, new PodSpec(), new PodStatusBuilder().withStartTime("2017-06-12T22:59Z").build());
    m.checking(new Expectations(){{
        allowing(myApi).getPodStatus(with("foo")); will(returnValue(pod.getStatus()));
    }});
    KubeCloudInstanceImpl instance = new KubeCloudInstanceImpl(image, pod);
    Date startedTime = instance.getStartedTime();
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm'Z'");
    dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
    assertEquals("2017-06-12T22:59Z", dateFormat.format(startedTime));
}
 
Example 11
Source File: IngressesTest.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
private Ingress createIngress(IngressBackend backend) {
  Ingress ingress = new Ingress();
  ObjectMeta ingressMeta = new ObjectMeta();
  ingressMeta.setName("ingressname");
  ingress.setMetadata(ingressMeta);
  IngressSpec ingressSpec = new IngressSpec();
  IngressRule ingressRule = new IngressRule();
  ingressRule.setHost("ingresshost");
  ingressRule.setHttp(
      new HTTPIngressRuleValue(singletonList(new HTTPIngressPath(backend, null))));
  ingressSpec.setRules(singletonList(ingressRule));
  ingress.setSpec(ingressSpec);
  return ingress;
}
 
Example 12
Source File: KafkaResourceListTest.java    From syndesis with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldDeserialize() throws IOException {
    final KafkaResourceList list = new YAMLMapper().readValue(KafkaResourceListTest.class.getResourceAsStream("/io/syndesis/connector/kafka/kafkas.yaml"),
        KafkaResourceList.class);

    assertThat(list).isNotNull();

    final List<Kafka> items = list.getItems();
    assertThat(items).hasSize(2);

    final Status myClusterStatus = new Status(Arrays.asList(
        new Listener("plain", Collections.singletonList(new Address("my-cluster-kafka-bootstrap.zregvart.svc", 9092))),
        new Listener("tls", Collections.singletonList(new Address("my-cluster-kafka-bootstrap.zregvart.svc", 9093)))));
    final Kafka myCluster = new Kafka(myClusterStatus);

    final ObjectMeta myClusterMetadata = myCluster.getMetadata();
    myClusterMetadata.setName("my-cluster");
    myClusterMetadata.setNamespace("zregvart");

    final Status zoransClusterStatus = new Status(Arrays.asList(
        new Listener("plain", Collections.singletonList(new Address("zorans-cluster-kafka-bootstrap.zregvart.svc", 9092))),
        new Listener("tls", Collections.singletonList(new Address("zorans-cluster-kafka-bootstrap.zregvart.svc", 9093)))));
    final Kafka zoransCluster = new Kafka(zoransClusterStatus);

    final ObjectMeta zoransClusterMetadata = zoransCluster.getMetadata();
    zoransClusterMetadata.setName("zorans-cluster");
    zoransClusterMetadata.setNamespace("zregvart");

    assertThat(items).contains(zoransCluster, zoransCluster);
}
 
Example 13
Source File: IstioExecutor.java    From istio-apim with Apache License 2.0 5 votes vote down vote up
/**
 * Create HTTPAPISpecBinding for the API
 *
 * @param apiName  Name of the API
 * @param endPoint Endpoint of the API
 */
public void createHttpAPISpecBinding(String apiName, String endPoint) {

    NonNamespaceOperation<HTTPAPISpecBinding, HTTPAPISpecBindingList, DoneableHTTPAPISpecBinding,
            io.fabric8.kubernetes.client.dsl.Resource<HTTPAPISpecBinding, DoneableHTTPAPISpecBinding>> bindingClient
            = client.customResource(httpAPISpecBindingCRD, HTTPAPISpecBinding.class, HTTPAPISpecBindingList.class,
            DoneableHTTPAPISpecBinding.class).inNamespace(appNamespace);

    String bindingName = Strings.toLowerCase(apiName) + "-binding";
    String apiSpecName = Strings.toLowerCase(apiName) + "-apispec";

    HTTPAPISpecBinding httpapiSpecBinding = new HTTPAPISpecBinding();
    ObjectMeta metadata = new ObjectMeta();
    metadata.setName(bindingName);
    httpapiSpecBinding.setMetadata(metadata);
    HTTPAPISpecBindingSpec httpapiSpecBindingSpec = new HTTPAPISpecBindingSpec();

    APISpec apiSpec = new APISpec();
    apiSpec.setName(apiSpecName);
    apiSpec.setNamespace(appNamespace);
    ArrayList<APISpec> apiSpecsList = new ArrayList<>();
    apiSpecsList.add(apiSpec);
    httpapiSpecBindingSpec.setApi_specs(apiSpecsList);

    Service service = new Service();
    service.setName(endPoint);
    service.setNamespace(appNamespace);
    ArrayList<Service> servicesList = new ArrayList<>();
    servicesList.add(service);
    httpapiSpecBindingSpec.setServices(servicesList);
    httpapiSpecBinding.setSpec(httpapiSpecBindingSpec);

    bindingClient.createOrReplace(httpapiSpecBinding);
    log.info("[HTTPAPISpecBinding] " + bindingName + " Created in the [Namespace] " + appNamespace + " for the"
            + " [API] " + apiName);
}
 
Example 14
Source File: TillerInstaller.java    From microbean-helm with Apache License 2.0 5 votes vote down vote up
protected Deployment createDeployment(String namespace,
                                      final String deploymentName,
                                      final int replicas,
                                      Map<String, String> labels,
                                      final Map<String, String> nodeSelector,
                                      final String serviceAccountName,
                                      final String imageName,
                                      final ImagePullPolicy imagePullPolicy,
                                      final int maxHistory,
                                      final boolean hostNetwork,
                                      final boolean tls,
                                      final boolean verifyTls) {
  namespace = normalizeNamespace(namespace);
  labels = normalizeLabels(labels);

  final Deployment deployment = new Deployment();

  final ObjectMeta metadata = new ObjectMeta();
  metadata.setNamespace(namespace);
  metadata.setName(normalizeDeploymentName(deploymentName));
  metadata.setLabels(labels);
  deployment.setMetadata(metadata);

  deployment.setSpec(this.createDeploymentSpec(Math.max(1, replicas),
                                               labels,
                                               nodeSelector,
                                               serviceAccountName,
                                               imageName,
                                               imagePullPolicy,
                                               maxHistory,
                                               namespace,
                                               hostNetwork,
                                               tls,
                                               verifyTls));
  return deployment;
}
 
Example 15
Source File: K8sNamespaceManagerTest.java    From onos with Apache License 2.0 5 votes vote down vote up
private static Namespace createK8sNamespace(String uid, String name) {
    ObjectMeta meta = new ObjectMeta();
    meta.setUid(uid);
    meta.setName(name);

    Namespace namespace = new Namespace();
    namespace.setApiVersion("v1");
    namespace.setKind("Namespace");
    namespace.setMetadata(meta);

    return namespace;
}
 
Example 16
Source File: K8sIngressManagerTest.java    From onos with Apache License 2.0 5 votes vote down vote up
private static Ingress createK8sIngress(String uid, String name) {
    ObjectMeta meta = new ObjectMeta();
    meta.setUid(uid);
    meta.setName(name);

    Ingress ingress = new Ingress();
    ingress.setApiVersion("v1");
    ingress.setKind("Ingress");
    ingress.setMetadata(meta);

    return ingress;
}
 
Example 17
Source File: PreviewUrlExposerTest.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void shouldProvisionIngressWhenNotFound() throws InternalInfrastructureException {
  Mockito.when(
          externalServiceExposureStrategy.getExternalPath(Mockito.anyString(), Mockito.any()))
      .thenReturn("some-server-path");

  final int PORT = 8080;
  final String SERVER_PORT_NAME = "server-" + PORT;
  final String SERVICE_NAME = "servicename";

  CommandImpl command =
      new CommandImpl("a", "a", "a", new PreviewUrlImpl(PORT, null), Collections.emptyMap());

  Service service = new Service();
  ObjectMeta serviceMeta = new ObjectMeta();
  serviceMeta.setName(SERVICE_NAME);
  service.setMetadata(serviceMeta);
  ServiceSpec serviceSpec = new ServiceSpec();
  serviceSpec.setPorts(
      singletonList(new ServicePort(SERVER_PORT_NAME, null, PORT, "TCP", new IntOrString(PORT))));
  service.setSpec(serviceSpec);

  Map<String, Service> services = new HashMap<>();
  services.put(SERVICE_NAME, service);

  KubernetesEnvironment env =
      KubernetesEnvironment.builder()
          .setCommands(singletonList(new CommandImpl(command)))
          .setServices(services)
          .setIngresses(new HashMap<>())
          .build();

  previewUrlExposer.expose(env);
  assertEquals(env.getIngresses().size(), 1);
  Ingress provisionedIngress = env.getIngresses().values().iterator().next();
  IngressBackend provisionedIngressBackend =
      provisionedIngress.getSpec().getRules().get(0).getHttp().getPaths().get(0).getBackend();
  assertEquals(provisionedIngressBackend.getServicePort().getStrVal(), SERVER_PORT_NAME);
  assertEquals(provisionedIngressBackend.getServiceName(), SERVICE_NAME);
}
 
Example 18
Source File: ServerPingRequestExecutorTest.java    From kubernetes-elastic-agents with Apache License 2.0 4 votes vote down vote up
@Test
public void testShouldTerminateUnregisteredInstances_forSingleCluster() throws Exception {
    String unregisteredAgentId1 = "unregisteredAgentId1-" + UUID.randomUUID().toString();
    String unregisteredAgentId2 = "unregisteredAgentId2-" + UUID.randomUUID().toString();

    long time = Calendar.getInstance().getTimeInMillis();
    Pod mockedPod = mock(Pod.class);
    when(mockedOperation.withName(anyString())).thenReturn(podResource);
    when(podResource.get()).thenReturn(mockedPod);
    objectMetadata = new ObjectMeta();
    objectMetadata.setLabels(Collections.singletonMap(JOB_ID_LABEL_KEY, "20"));
    objectMetadata.setName(unregisteredAgentId1);
    objectMetadata.setCreationTimestamp(getSimpleDateFormat().format(new Date(time - (20 * 60000))));

    when(mockedPod.getMetadata()).thenReturn(objectMetadata);

    ClusterProfileProperties clusterProfilePropertiesForCluster1 = new ClusterProfileProperties("https://localhost:8154/go", null, null);

    KubernetesInstance k8sUnregisteredCluster1Pod1 = new KubernetesInstance(new DateTime().minusMinutes(100), null, unregisteredAgentId1, Collections.emptyMap(), 3L, PodState.Running);
    KubernetesInstance k8sUnregisteredCluster1Pod2 = new KubernetesInstance(new DateTime(), null, unregisteredAgentId2, Collections.emptyMap(), 3L, PodState.Running);

    final Agents allAgentsInitially = new Agents();

    KubernetesAgentInstances agentInstancesForCluster1 = new KubernetesAgentInstances(factory);
    agentInstancesForCluster1.register(k8sUnregisteredCluster1Pod1);
    agentInstancesForCluster1.register(k8sUnregisteredCluster1Pod2);

    HashMap<String, KubernetesAgentInstances> clusterSpecificInstances = new HashMap<>();
    clusterSpecificInstances.put(clusterProfilePropertiesForCluster1.uuid(), agentInstancesForCluster1);

    ServerPingRequest serverPingRequest = mock(ServerPingRequest.class);
    when(serverPingRequest.allClusterProfileProperties()).thenReturn(Arrays.asList(clusterProfilePropertiesForCluster1));

    PluginRequest pluginRequest = mock(PluginRequest.class);

    when(pluginRequest.listAgents()).thenReturn(allAgentsInitially);

    assertTrue(clusterSpecificInstances.get(clusterProfilePropertiesForCluster1.uuid()).hasInstance(k8sUnregisteredCluster1Pod1.name()));
    assertTrue(clusterSpecificInstances.get(clusterProfilePropertiesForCluster1.uuid()).hasInstance(k8sUnregisteredCluster1Pod2.name()));

    new ServerPingRequestExecutor(serverPingRequest, clusterSpecificInstances, pluginRequest).execute();

    assertFalse(clusterSpecificInstances.get(clusterProfilePropertiesForCluster1.uuid()).hasInstance(k8sUnregisteredCluster1Pod1.name()));
    assertTrue(clusterSpecificInstances.get(clusterProfilePropertiesForCluster1.uuid()).hasInstance(k8sUnregisteredCluster1Pod2.name()));
}
 
Example 19
Source File: PreviewUrlExposerTest.java    From che with Eclipse Public License 2.0 4 votes vote down vote up
@Test
public void shouldNotProvisionWhenServiceAndIngressFound()
    throws InternalInfrastructureException {
  final int PORT = 8080;
  final String SERVER_PORT_NAME = "server-" + PORT;

  CommandImpl command =
      new CommandImpl("a", "a", "a", new PreviewUrlImpl(PORT, null), Collections.emptyMap());

  Service service = new Service();
  ObjectMeta serviceMeta = new ObjectMeta();
  serviceMeta.setName("servicename");
  service.setMetadata(serviceMeta);
  ServiceSpec serviceSpec = new ServiceSpec();
  serviceSpec.setPorts(
      singletonList(new ServicePort(SERVER_PORT_NAME, null, PORT, "TCP", new IntOrString(PORT))));
  service.setSpec(serviceSpec);

  Ingress ingress = new Ingress();
  ObjectMeta ingressMeta = new ObjectMeta();
  ingressMeta.setName("ingressname");
  ingress.setMetadata(ingressMeta);
  IngressSpec ingressSpec = new IngressSpec();
  IngressRule ingressRule = new IngressRule();
  ingressRule.setHost("ingresshost");
  IngressBackend ingressBackend =
      new IngressBackend("servicename", new IntOrString(SERVER_PORT_NAME));
  ingressRule.setHttp(
      new HTTPIngressRuleValue(singletonList(new HTTPIngressPath(ingressBackend, null))));
  ingressSpec.setRules(singletonList(ingressRule));
  ingress.setSpec(ingressSpec);

  Map<String, Service> services = new HashMap<>();
  services.put("servicename", service);
  Map<String, Ingress> ingresses = new HashMap<>();
  ingresses.put("ingressname", ingress);

  KubernetesEnvironment env =
      KubernetesEnvironment.builder()
          .setCommands(singletonList(new CommandImpl(command)))
          .setServices(services)
          .setIngresses(ingresses)
          .build();

  assertEquals(env.getIngresses().size(), 1);
  previewUrlExposer.expose(env);
  assertEquals(env.getIngresses().size(), 1);
}
 
Example 20
Source File: IstioExecutor.java    From istio-apim with Apache License 2.0 4 votes vote down vote up
/**
 * Create HTTPAPISpec for the API
 *
 * @param apiName        Name of the API
 * @param apiContext     Context of the API
 * @param apiVersion     Version of the API
 * @param uriTemplates   URI templates of the API
 * @param resourceScopes Scopes of the resources of the API
 */
public void createHTTPAPISpec(String apiName, String apiContext, String apiVersion, Set<URITemplate> uriTemplates,
                              HashMap<String, String> resourceScopes) {

    NonNamespaceOperation<HTTPAPISpec, HTTPAPISpecList, DoneableHTTPAPISpec,
            io.fabric8.kubernetes.client.dsl.Resource<HTTPAPISpec, DoneableHTTPAPISpec>> apiSpecClient
            = client.customResource(httpAPISpecCRD, HTTPAPISpec.class, HTTPAPISpecList.class,
            DoneableHTTPAPISpec.class).inNamespace(appNamespace);

    String apiSpecName = Strings.toLowerCase(apiName) + "-apispec";

    HTTPAPISpec httpapiSpec = new HTTPAPISpec();
    ObjectMeta metadata = new ObjectMeta();
    metadata.setName(apiSpecName);
    httpapiSpec.setMetadata(metadata);

    HTTPAPISpecSpec httpapiSpecSpec = new HTTPAPISpecSpec();
    Map<String, Map<String, String>> attributeList = new HashMap<>();

    Map<String, String> apiService = new HashMap<>();
    apiService.put("stringValue", apiName);
    attributeList.put("api.service", apiService);

    Map<String, String> apiContextValue = new HashMap<>();
    apiContextValue.put("stringValue", apiContext);
    attributeList.put("api.context", apiContextValue);

    Map<String, String> apiVersionValue = new HashMap<>();
    apiVersionValue.put("stringValue", apiVersion);
    attributeList.put("api.version", apiVersionValue);

    Attributes attributes = new Attributes();
    attributes.setAttributes(attributeList);
    httpapiSpecSpec.setAttributes(attributes);
    httpapiSpecSpec.setPatterns(getPatterns(apiContext, apiVersion, uriTemplates, resourceScopes));
    httpapiSpec.setSpec(httpapiSpecSpec);

    apiSpecClient.createOrReplace(httpapiSpec);
    log.info("[HTTPAPISpec] " + apiSpecName + " Created in the [Namespace] " + appNamespace + " for the"
            + " [API] " + apiName);
}