Import k8s client deps, support inject k8s API server config

Change-Id: Iaf246a06462b8a878e93ef3f98da399c3600b129
diff --git a/apps/k8s-node/api/src/main/java/org/onosproject/k8snode/api/DefaultK8sApiConfig.java b/apps/k8s-node/api/src/main/java/org/onosproject/k8snode/api/DefaultK8sApiConfig.java
new file mode 100644
index 0000000..157763f
--- /dev/null
+++ b/apps/k8s-node/api/src/main/java/org/onosproject/k8snode/api/DefaultK8sApiConfig.java
@@ -0,0 +1,202 @@
+/*
+ * Copyright 2019-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.k8snode.api;
+
+import com.google.common.base.MoreObjects;
+import org.onlab.packet.IpAddress;
+
+import java.util.Objects;
+
+import static com.google.common.base.Preconditions.checkArgument;
+import static org.onosproject.k8snode.api.K8sApiConfig.Scheme.HTTPS;
+
+/**
+ * Default implementation of kubernetes API configuration.
+ */
+public final class DefaultK8sApiConfig implements K8sApiConfig {
+
+    private static final String NOT_NULL_MSG = "API Config % cannot be null";
+
+    private final Scheme scheme;
+    private final IpAddress ipAddress;
+    private final int port;
+    private final String token;
+    private final String caCertData;
+    private final String clientCertData;
+    private final String clientKeyData;
+
+    private DefaultK8sApiConfig(Scheme scheme, IpAddress ipAddress, int port,
+                                String token, String caCertData,
+                                String clientCertData, String clientKeyData) {
+        this.scheme = scheme;
+        this.ipAddress = ipAddress;
+        this.port = port;
+        this.token = token;
+        this.caCertData = caCertData;
+        this.clientCertData = clientCertData;
+        this.clientKeyData = clientKeyData;
+    }
+
+    @Override
+    public Scheme scheme() {
+        return scheme;
+    }
+
+    @Override
+    public IpAddress ipAddress() {
+        return ipAddress;
+    }
+
+    @Override
+    public int port() {
+        return port;
+    }
+
+    @Override
+    public String token() {
+        return token;
+    }
+
+    @Override
+    public String caCertData() {
+        return caCertData;
+    }
+
+    @Override
+    public String clientCertData() {
+        return clientCertData;
+    }
+
+    @Override
+    public String clientKeyData() {
+        return clientKeyData;
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) {
+            return true;
+        }
+        if (o == null || getClass() != o.getClass()) {
+            return false;
+        }
+        DefaultK8sApiConfig that = (DefaultK8sApiConfig) o;
+        return port == that.port &&
+                scheme == that.scheme &&
+                ipAddress.equals(that.ipAddress) &&
+                token.equals(that.token) &&
+                caCertData.equals(that.caCertData) &&
+                clientCertData.equals(that.clientCertData) &&
+                clientKeyData.equals(that.clientKeyData);
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hash(scheme, ipAddress, port, token, caCertData,
+                clientCertData, clientKeyData);
+    }
+
+    @Override
+    public String toString() {
+        return MoreObjects.toStringHelper(this)
+                .add("scheme", scheme)
+                .add("ipAddress", ipAddress)
+                .add("port", port)
+                .add("token", token)
+                .add("caCertData", caCertData)
+                .add("clientCertData", clientCertData)
+                .add("clientKeyData", clientKeyData)
+                .toString();
+    }
+
+    /**
+     * Returns new builder instance.
+     *
+     * @return kubernetes API server config builder
+     */
+    public static Builder builder() {
+        return new Builder();
+    }
+
+    public static final class Builder implements K8sApiConfig.Builder {
+
+        private Scheme scheme;
+        private IpAddress ipAddress;
+        private int port;
+        private String token;
+        private String caCertData;
+        private String clientCertData;
+        private String clientKeyData;
+
+        @Override
+        public K8sApiConfig build() {
+            checkArgument(scheme != null, NOT_NULL_MSG, "scheme");
+            checkArgument(ipAddress != null, NOT_NULL_MSG, "ipAddress");
+
+            if (scheme == HTTPS) {
+                checkArgument(token != null, NOT_NULL_MSG, "token");
+                checkArgument(caCertData != null, NOT_NULL_MSG, "caCertData");
+                checkArgument(clientCertData != null, NOT_NULL_MSG, "clientCertData");
+                checkArgument(clientKeyData != null, NOT_NULL_MSG, "clientKeyData");
+            }
+
+            return new DefaultK8sApiConfig(scheme, ipAddress, port, token,
+                    caCertData, clientCertData, clientKeyData);
+        }
+
+        @Override
+        public Builder scheme(Scheme scheme) {
+            this.scheme = scheme;
+            return this;
+        }
+
+        @Override
+        public Builder ipAddress(IpAddress ipAddress) {
+            this.ipAddress = ipAddress;
+            return this;
+        }
+
+        @Override
+        public Builder port(int port) {
+            this.port = port;
+            return this;
+        }
+
+        @Override
+        public Builder token(String token) {
+            this.token = token;
+            return this;
+        }
+
+        @Override
+        public Builder caCertData(String caCertData) {
+            this.caCertData = caCertData;
+            return this;
+        }
+
+        @Override
+        public Builder clientCertData(String clientCertData) {
+            this.clientCertData = clientCertData;
+            return this;
+        }
+
+        @Override
+        public Builder clientKeyData(String clientKeyData) {
+            this.clientKeyData = clientKeyData;
+            return this;
+        }
+    }
+}
diff --git a/apps/k8s-node/api/src/main/java/org/onosproject/k8snode/api/DefaultK8sNode.java b/apps/k8s-node/api/src/main/java/org/onosproject/k8snode/api/DefaultK8sNode.java
index 5f22f70..76b845c 100644
--- a/apps/k8s-node/api/src/main/java/org/onosproject/k8snode/api/DefaultK8sNode.java
+++ b/apps/k8s-node/api/src/main/java/org/onosproject/k8snode/api/DefaultK8sNode.java
@@ -59,7 +59,8 @@
      * @param state             node state
      */
     protected DefaultK8sNode(String hostname, Type type, DeviceId intgBridge,
-                             IpAddress managementIp, IpAddress dataIp, K8sNodeState state) {
+                             IpAddress managementIp, IpAddress dataIp,
+                             K8sNodeState state) {
         this.hostname = hostname;
         this.type = type;
         this.intgBridge = intgBridge;
@@ -222,6 +223,7 @@
         private IpAddress managementIp;
         private IpAddress dataIp;
         private K8sNodeState state;
+        private K8sApiConfig apiConfig;
 
         // private constructor not intended to use from external
         private Builder() {
diff --git a/apps/k8s-node/api/src/main/java/org/onosproject/k8snode/api/K8sApiConfig.java b/apps/k8s-node/api/src/main/java/org/onosproject/k8snode/api/K8sApiConfig.java
new file mode 100644
index 0000000..0c63733
--- /dev/null
+++ b/apps/k8s-node/api/src/main/java/org/onosproject/k8snode/api/K8sApiConfig.java
@@ -0,0 +1,157 @@
+/*
+ * Copyright 2019-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.k8snode.api;
+
+import org.onlab.packet.IpAddress;
+
+/**
+ * Representation of configuration used in kubernetes API server.
+ */
+public interface K8sApiConfig {
+
+    /**
+     * Lists of authentication schemes.
+     */
+    enum Scheme {
+        /**
+         * Signifies that this is a HTTP authentication scheme.
+         */
+        HTTP,
+
+        /**
+         * Signifies that this is a HTTPS authentication scheme.
+         */
+        HTTPS,
+    }
+
+    /**
+     * Returns the authentication scheme.
+     *
+     * @return authentication scheme
+     */
+    Scheme scheme();
+
+    /**
+     * Returns the IP address of kubernetes API server.
+     *
+     * @return IP address of kubernetes API server
+     */
+    IpAddress ipAddress();
+
+    /**
+     * Returns the port number of kubernetes API server.
+     *
+     * @return port number of kubernetes API server
+     */
+    int port();
+
+    /**
+     * Returns the token used for authenticating to API server.
+     *
+     * @return token value
+     */
+    String token();
+
+    /**
+     * Returns the CA certificate data.
+     *
+     * @return CA certificate data
+     */
+    String caCertData();
+
+    /**
+     * Returns the client certificate data.
+     *
+     * @return client certificate data
+     */
+    String clientCertData();
+
+    /**
+     * Returns the client key data.
+     *
+     * @return client key data
+     */
+    String clientKeyData();
+
+    /**
+     * Builder of new API config entity.
+     */
+    interface Builder {
+
+        /**
+         * Builds an immutable kubernetes API config instance.
+         *
+         * @return kubernetes API config instance
+         */
+        K8sApiConfig build();
+
+        /**
+         * Returns kubernetes API server config builder with supplied scheme.
+         *
+         * @param scheme scheme of authentication
+         * @return kubernetes API config builder
+         */
+        Builder scheme(Scheme scheme);
+
+        /**
+         * Returns kubernetes API server config builder with supplied IP address.
+         *
+         * @param ipAddress IP address of kubernetes API server
+         * @return kubernetes API config builder
+         */
+        Builder ipAddress(IpAddress ipAddress);
+
+        /**
+         * Returns kubernetes API server config builder with supplied port number.
+         *
+         * @param port port number of kubernetes API server
+         * @return kubernetes API config builder
+         */
+        Builder port(int port);
+
+        /**
+         * Returns kubernetes API server config builder with supplied token.
+         *
+         * @param token token for authentication
+         * @return kubernetes API config builder
+         */
+        Builder token(String token);
+
+        /**
+         * Returns kubernetes API server config builder with supplied CA certificate data.
+         *
+         * @param caCertData CA certificate data
+         * @return kubernetes API config builder
+         */
+        Builder caCertData(String caCertData);
+
+        /**
+         * Returns kubernetes API server config builder with supplied client certificate data.
+         *
+         * @param clientCertData client certificate data
+         * @return kubernetes API config builder
+         */
+        Builder clientCertData(String clientCertData);
+
+        /**
+         * Returns kubernetes API server config builder with supplied client key data.
+         *
+         * @param clientKeyData client key data
+         * @return kubernetes API config builder
+         */
+        Builder clientKeyData(String clientKeyData);
+    }
+}
diff --git a/apps/k8s-node/api/src/main/java/org/onosproject/k8snode/api/K8sApiConfigAdminService.java b/apps/k8s-node/api/src/main/java/org/onosproject/k8snode/api/K8sApiConfigAdminService.java
new file mode 100644
index 0000000..4f96f78
--- /dev/null
+++ b/apps/k8s-node/api/src/main/java/org/onosproject/k8snode/api/K8sApiConfigAdminService.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright 2019-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.k8snode.api;
+
+import org.onlab.packet.IpAddress;
+
+/**
+ * Service for administering inventory of kubernetes API configs.
+ */
+public interface K8sApiConfigAdminService extends K8sApiConfigService {
+
+    /**
+     * Creates an API config.
+     *
+     * @param config kubernetes API server config
+     */
+    void createApiConfig(K8sApiConfig config);
+
+    /**
+     * Updates the API config.
+     *
+     * @param config kubernetes API server config
+     */
+    void updateApiConfig(K8sApiConfig config);
+
+    /**
+     * Removes the API config.
+     *
+     * @param endpoint kubernetes API endpoint
+     * @return removed kubernetes API server config; null if no config
+     *         associated with the endpoint
+     */
+    K8sApiConfig removeApiConfig(String endpoint);
+
+    /**
+     * Removes the kubernetes API config with the given scheme, IP and port.
+     *
+     * @param scheme        scheme (HTTP/HTTPS)
+     * @param ipAddress     IP address of API server
+     * @param port          port number of API server
+     * @return removed kubernetes API server config; null if no config
+     *         associated with the scheme, IP and port
+     */
+    K8sApiConfig removeApiConfig(K8sApiConfig.Scheme scheme, IpAddress ipAddress, int port);
+}
diff --git a/apps/k8s-node/api/src/main/java/org/onosproject/k8snode/api/K8sApiConfigEvent.java b/apps/k8s-node/api/src/main/java/org/onosproject/k8snode/api/K8sApiConfigEvent.java
new file mode 100644
index 0000000..1b85dc9
--- /dev/null
+++ b/apps/k8s-node/api/src/main/java/org/onosproject/k8snode/api/K8sApiConfigEvent.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2019-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.k8snode.api;
+
+import org.onosproject.event.AbstractEvent;
+
+/**
+ * Describes kubernetes API server config event.
+ */
+public class K8sApiConfigEvent extends AbstractEvent<K8sApiConfigEvent.Type, K8sApiConfig> {
+
+    /**
+     * Lists of kubernetes API server config event types.
+     */
+    public enum Type {
+        /**
+         * Signifies that API config is created.
+         */
+        K8S_API_CONFIG_CREATED,
+
+        /**
+         * Signifies that API config is updated.
+         */
+        K8S_API_CONFIG_UPDATED,
+
+        /**
+         * Signifies that API config is removed.
+         */
+        K8S_API_CONFIG_REMOVED,
+    }
+
+    /**
+     * Creates an event with the given type and node.
+     *
+     * @param type event type
+     * @param subject kubernetes API config
+     */
+    public K8sApiConfigEvent(Type type, K8sApiConfig subject) {
+        super(type, subject);
+    }
+}
diff --git a/apps/k8s-node/api/src/main/java/org/onosproject/k8snode/api/K8sApiConfigListener.java b/apps/k8s-node/api/src/main/java/org/onosproject/k8snode/api/K8sApiConfigListener.java
new file mode 100644
index 0000000..4901b80
--- /dev/null
+++ b/apps/k8s-node/api/src/main/java/org/onosproject/k8snode/api/K8sApiConfigListener.java
@@ -0,0 +1,24 @@
+/*
+ * Copyright 2019-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.k8snode.api;
+
+import org.onosproject.event.EventListener;
+
+/**
+ * Listener for kubernetes API config event.
+ */
+public interface K8sApiConfigListener extends EventListener<K8sApiConfigEvent> {
+}
diff --git a/apps/k8s-node/api/src/main/java/org/onosproject/k8snode/api/K8sApiConfigService.java b/apps/k8s-node/api/src/main/java/org/onosproject/k8snode/api/K8sApiConfigService.java
new file mode 100644
index 0000000..42ef15e
--- /dev/null
+++ b/apps/k8s-node/api/src/main/java/org/onosproject/k8snode/api/K8sApiConfigService.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright 2019-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.k8snode.api;
+
+import org.onlab.packet.IpAddress;
+import org.onosproject.event.ListenerService;
+import org.onosproject.k8snode.api.K8sApiConfig.Scheme;
+
+import java.util.Set;
+
+/**
+ * Service for interfacing with the inventory of kubernetes API server config.
+ */
+public interface K8sApiConfigService
+        extends ListenerService<K8sApiConfigEvent, K8sApiConfigListener> {
+    String APP_ID = "org.onosproject.k8snode";
+
+    /**
+     * Returns all registered API configs.
+     *
+     * @return set of kubernetes API configs
+     */
+    Set<K8sApiConfig> apiConfigs();
+
+    /**
+     * Returns the API config with the specified endpoint.
+     *
+     * @param endpoint endpoint
+     * @return kubernetes API config
+     */
+    K8sApiConfig apiConfig(String endpoint);
+
+    /**
+     * Returns the API config with the specified scheme, IP and port.
+     *
+     * @param scheme        scheme (HTTP/HTTPS)
+     * @param ipAddress     IP address of API server
+     * @param port          port number of API server
+     * @return kubernetes API config
+     */
+    K8sApiConfig apiConfig(Scheme scheme, IpAddress ipAddress, int port);
+}
diff --git a/apps/k8s-node/api/src/main/java/org/onosproject/k8snode/api/K8sApiConfigStore.java b/apps/k8s-node/api/src/main/java/org/onosproject/k8snode/api/K8sApiConfigStore.java
new file mode 100644
index 0000000..0f8f221
--- /dev/null
+++ b/apps/k8s-node/api/src/main/java/org/onosproject/k8snode/api/K8sApiConfigStore.java
@@ -0,0 +1,89 @@
+/*
+ * Copyright 2019-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.k8snode.api;
+
+import org.onlab.packet.IpAddress;
+import org.onosproject.k8snode.api.K8sApiConfig.Scheme;
+import org.onosproject.store.Store;
+
+import java.util.Set;
+
+/**
+ * Manages inventory of kubernetes API config; not intended for direct use.
+ */
+public interface K8sApiConfigStore
+        extends Store<K8sApiConfigEvent, K8sApiConfigStoreDelegate> {
+
+    /**
+     * Creates a API config.
+     *
+     * @param config kubernetes API server config
+     */
+    void createApiConfig(K8sApiConfig config);
+
+    /**
+     * Updates the API config.
+     *
+     * @param config kubernetes API server config
+     */
+    void updateApiConfig(K8sApiConfig config);
+
+    /**
+     * Removes the kubernetes API config with the given endpoint.
+     * Endpoint comprises of scheme (HTTP), IP address and port
+     *
+     * @param endpoint kubernetes API endpoint
+     * @return removed kubernetes API server config; null if no config
+     *         associated with the endpoint
+     */
+    K8sApiConfig removeApiConfig(String endpoint);
+
+    /**
+     * Removes the kubernetes API config with the given scheme, IP and port.
+     *
+     * @param scheme        scheme (HTTP/HTTPS)
+     * @param ipAddress     IP address of API server
+     * @param port          port number of API server
+     * @return removed kubernetes API server config; null if no config
+     *         associated with the scheme, IP and port
+     */
+    K8sApiConfig removeApiConfig(Scheme scheme, IpAddress ipAddress, int port);
+
+    /**
+     * Returns all registered kubernetes API configs.
+     *
+     * @return set of kubernetes API configs
+     */
+    Set<K8sApiConfig> apiConfigs();
+
+    /**
+     * Returns the API config with the specified endpoint.
+     *
+     * @param endpoint endpoint
+     * @return kubernetes API config
+     */
+    K8sApiConfig apiConfig(String endpoint);
+
+    /**
+     * Returns the API config with the specified scheme, IP and port.
+     *
+     * @param scheme        scheme (HTTP/HTTPS)
+     * @param ipAddress     IP address of API server
+     * @param port          port number of API server
+     * @return kubernetes API config
+     */
+    K8sApiConfig apiConfig(Scheme scheme, IpAddress ipAddress, int port);
+}
diff --git a/apps/k8s-node/api/src/main/java/org/onosproject/k8snode/api/K8sApiConfigStoreDelegate.java b/apps/k8s-node/api/src/main/java/org/onosproject/k8snode/api/K8sApiConfigStoreDelegate.java
new file mode 100644
index 0000000..11ee5f9
--- /dev/null
+++ b/apps/k8s-node/api/src/main/java/org/onosproject/k8snode/api/K8sApiConfigStoreDelegate.java
@@ -0,0 +1,24 @@
+/*
+ * Copyright 2019-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.k8snode.api;
+
+import org.onosproject.store.StoreDelegate;
+
+/**
+ * Kubernetes API server config store delegate.
+ */
+public interface K8sApiConfigStoreDelegate extends StoreDelegate<K8sApiConfigEvent> {
+}
diff --git a/apps/k8s-node/api/src/test/java/org/onosproject/k8snode/api/DefaultK8sApiConfigTest.java b/apps/k8s-node/api/src/test/java/org/onosproject/k8snode/api/DefaultK8sApiConfigTest.java
new file mode 100644
index 0000000..55e56f1
--- /dev/null
+++ b/apps/k8s-node/api/src/test/java/org/onosproject/k8snode/api/DefaultK8sApiConfigTest.java
@@ -0,0 +1,128 @@
+/*
+ * Copyright 2019-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.k8snode.api;
+
+import com.google.common.testing.EqualsTester;
+import org.junit.Before;
+import org.junit.Test;
+import org.onlab.packet.IpAddress;
+import org.onosproject.k8snode.api.K8sApiConfig.Scheme;
+
+import static junit.framework.TestCase.assertEquals;
+import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
+import static org.onosproject.k8snode.api.K8sApiConfig.Scheme.HTTP;
+import static org.onosproject.k8snode.api.K8sApiConfig.Scheme.HTTPS;
+
+/**
+ * Unit tests for DefaultK8sApiConfig.
+ */
+public final class DefaultK8sApiConfigTest {
+
+    private static final Scheme SCHEME_1 = HTTP;
+    private static final Scheme SCHEME_2 = HTTPS;
+
+    private static final IpAddress IP_ADDRESS_1 = IpAddress.valueOf("192.168.0.200");
+    private static final IpAddress IP_ADDRESS_2 = IpAddress.valueOf("192.168.0.201");
+
+    private static final int PORT_1 = 6443;
+    private static final int PORT_2 = 443;
+
+    private static final String TOKEN_1 = "token1";
+    private static final String TOKEN_2 = "token2";
+
+    private static final String CA_CERT_DATA_1 = "caCertData1";
+    private static final String CA_CERT_DATA_2 = "caCertData2";
+
+    private static final String CLIENT_CERT_DATA_1 = "clientCertData1";
+    private static final String CLIENT_CERT_DATA_2 = "clientCertData2";
+
+    private static final String CLIENT_KEY_DATA_1 = "clientKeyData1";
+    private static final String CLIENT_KEY_DATA_2 = "clientKeyData2";
+
+    private K8sApiConfig config1;
+    private K8sApiConfig sameAsConfig1;
+    private K8sApiConfig config2;
+
+    /**
+     * Tests class immutability.
+     */
+    @Test
+    public void testImmutability() {
+        assertThatClassIsImmutable(DefaultK8sApiConfig.class);
+    }
+
+    /**
+     * Initial setup for this unit test.
+     */
+    @Before
+    public void setUp() {
+        config1 = DefaultK8sApiConfig.builder()
+                .scheme(SCHEME_1)
+                .ipAddress(IP_ADDRESS_1)
+                .port(PORT_1)
+                .token(TOKEN_1)
+                .caCertData(CA_CERT_DATA_1)
+                .clientCertData(CLIENT_CERT_DATA_1)
+                .clientKeyData(CLIENT_KEY_DATA_1)
+                .build();
+
+        sameAsConfig1 = DefaultK8sApiConfig.builder()
+                .scheme(SCHEME_1)
+                .ipAddress(IP_ADDRESS_1)
+                .port(PORT_1)
+                .token(TOKEN_1)
+                .caCertData(CA_CERT_DATA_1)
+                .clientCertData(CLIENT_CERT_DATA_1)
+                .clientKeyData(CLIENT_KEY_DATA_1)
+                .build();
+
+        config2 = DefaultK8sApiConfig.builder()
+                .scheme(SCHEME_2)
+                .ipAddress(IP_ADDRESS_2)
+                .port(PORT_2)
+                .token(TOKEN_2)
+                .caCertData(CA_CERT_DATA_2)
+                .clientCertData(CLIENT_CERT_DATA_2)
+                .clientKeyData(CLIENT_KEY_DATA_2)
+                .build();
+    }
+
+    /**
+     * Tests object equality.
+     */
+    @Test
+    public void testEquality() {
+        new EqualsTester().addEqualityGroup(config1, sameAsConfig1)
+                .addEqualityGroup(config2)
+                .testEquals();
+    }
+
+    /**
+     * Test object construction.
+     */
+    @Test
+    public void testConstruction() {
+        K8sApiConfig config = config1;
+
+        assertEquals(SCHEME_1, config.scheme());
+        assertEquals(IP_ADDRESS_1, config.ipAddress());
+        assertEquals(PORT_1, config.port());
+        assertEquals(TOKEN_1, config.token());
+        assertEquals(CA_CERT_DATA_1, config.caCertData());
+        assertEquals(CLIENT_CERT_DATA_1, config.clientCertData());
+        assertEquals(CLIENT_KEY_DATA_1, config.clientKeyData());
+    }
+}