Esempio n. 1
0
        public async void ListNamespacePods_Basic_Works()
        {
            // Arrange
            var k8sMockResponse = @"{""kind"":""PodList"",""apiVersion"":""v1"",""metadata"":{""selfLink"":""/api/v1/namespaces/gerd/pods"",""resourceVersion"":""1762810""},""items"":[{""metadata"":{""name"":""nginx-1493591563-xb2v4"",""generateName"":""nginx-1493591563-"",""namespace"":""default"",""selfLink"":""/api/v1/namespaces/gerd/pods/nginx-1493591563-xb2v4"",""uid"":""ac1abb94-9c58-11e7-aaf5-00155d744505"",""resourceVersion"":""1737928"",""creationTimestamp"":""2017-09-18T10:03:51Z"",""labels"":{""app"":""nginx"",""pod-template-hash"":""1493591563""},""annotations"":{""kubernetes.io/created-by"":""{\""kind\"":\""SerializedReference\"",\""apiVersion\"":\""v1\"",\""reference\"":{\""kind\"":\""ReplicaSet\"",\""namespace\"":\""default\"",\""name\"":\""nginx-1493591563\"",\""uid\"":\""ac013b63-9c58-11e7-aaf5-00155d744505\"",\""apiVersion\"":\""extensions\"",\""resourceVersion\"":\""5306\""}}\n""},""ownerReferences"":[{""apiVersion"":""extensions/v1beta1"",""kind"":""ReplicaSet"",""name"":""nginx-1493591563"",""uid"":""ac013b63-9c58-11e7-aaf5-00155d744505"",""controller"":true,""blockOwnerDeletion"":true}]},""spec"":{""volumes"":[{""name"":""default-token-3zzcj"",""secret"":{""secretName"":""default-token-3zzcj"",""defaultMode"":420}}],""containers"":[{""name"":""nginx"",""image"":""nginx"",""resources"":{},""volumeMounts"":[{""name"":""default-token-3zzcj"",""readOnly"":true,""mountPath"":""/var/run/secrets/kubernetes.io/serviceaccount""}],""terminationMessagePath"":""/dev/termination-log"",""terminationMessagePolicy"":""File"",""imagePullPolicy"":""Always""}],""restartPolicy"":""Always"",""terminationGracePeriodSeconds"":30,""dnsPolicy"":""ClusterFirst"",""serviceAccountName"":""default"",""serviceAccount"":""default"",""nodeName"":""ubuntu"",""securityContext"":{},""schedulerName"":""default-scheduler""},""status"":{""phase"":""Running"",""conditions"":[{""type"":""Initialized"",""status"":""True"",""lastProbeTime"":null,""lastTransitionTime"":""2017-09-18T10:03:51Z""},{""type"":""Ready"",""status"":""True"",""lastProbeTime"":null,""lastTransitionTime"":""2017-10-12T07:09:21Z""},{""type"":""PodScheduled"",""status"":""True"",""lastProbeTime"":null,""lastTransitionTime"":""2017-09-18T10:03:51Z""}],""hostIP"":""192.168.188.42"",""podIP"":""172.17.0.5"",""startTime"":""2017-09-18T10:03:51Z"",""containerStatuses"":[{""name"":""nginx"",""state"":{""running"":{""startedAt"":""2017-10-12T07:09:20Z""}},""lastState"":{""terminated"":{""exitCode"":0,""reason"":""Completed"",""startedAt"":""2017-10-10T21:35:51Z"",""finishedAt"":""2017-10-12T07:07:37Z"",""containerID"":""docker://94df3f3965807421ad6dc76618e00b76cb15d024919c4946f3eb46a92659c62a""}},""ready"":true,""restartCount"":7,""image"":""nginx:latest"",""imageID"":""docker-pullable://nginx@sha256:004ac1d5e791e705f12a17c80d7bb1e8f7f01aa7dca7deee6e65a03465392072"",""containerID"":""docker://fa11bdd48c9b7d3a6c4c3f9b6d7319743c3455ab8d00c57d59c083b319b88194""}],""qosClass"":""BestEffort""}},{""metadata"":{""name"":""nginx-1493591564-xb2v4"",""generateName"":""nginx-1493591564-"",""namespace"":""default"",""selfLink"":""/api/v1/namespaces/gerd/pods/nginx-1493591564-xb2v4"",""uid"":""ac1abb94-9c58-11e7-aaf5-00155d744504"",""resourceVersion"":""1737928"",""creationTimestamp"":""2017-09-18T10:03:51Z"",""labels"":{""app"":""nginx"",""pod-template-hash"":""1493591564""},""annotations"":{""kubernetes.io/created-by"":""{\""kind\"":\""SerializedReference\"",\""apiVersion\"":\""v1\"",\""reference\"":{\""kind\"":\""ReplicaSet\"",\""namespace\"":\""default\"",\""name\"":\""nginx-1493591563\"",\""uid\"":\""ac013b63-9c58-11e7-aaf5-00155d744505\"",\""apiVersion\"":\""extensions\"",\""resourceVersion\"":\""5306\""}}\n""},""ownerReferences"":[{""apiVersion"":""extensions/v1beta1"",""kind"":""ReplicaSet"",""name"":""nginx-1493591563"",""uid"":""ac013b63-9c58-11e7-aaf5-00155d744505"",""controller"":true,""blockOwnerDeletion"":true}]},""spec"":{""volumes"":[{""name"":""default-token-3zzcj"",""secret"":{""secretName"":""default-token-3zzcj"",""defaultMode"":420}}],""containers"":[{""name"":""nginx"",""image"":""nginx"",""resources"":{},""volumeMounts"":[{""name"":""default-token-3zzcj"",""readOnly"":true,""mountPath"":""/var/run/secrets/kubernetes.io/serviceaccount""}],""terminationMessagePath"":""/dev/termination-log"",""terminationMessagePolicy"":""File"",""imagePullPolicy"":""Always""}],""restartPolicy"":""Always"",""terminationGracePeriodSeconds"":30,""dnsPolicy"":""ClusterFirst"",""serviceAccountName"":""default"",""serviceAccount"":""default"",""nodeName"":""ubuntu"",""securityContext"":{},""schedulerName"":""default-scheduler""},""status"":{""phase"":""Running"",""conditions"":[{""type"":""Initialized"",""status"":""True"",""lastProbeTime"":null,""lastTransitionTime"":""2017-09-18T10:03:51Z""},{""type"":""Ready"",""status"":""True"",""lastProbeTime"":null,""lastTransitionTime"":""2017-10-12T07:09:21Z""},{""type"":""PodScheduled"",""status"":""True"",""lastProbeTime"":null,""lastTransitionTime"":""2017-09-18T10:03:51Z""}],""hostIP"":""192.168.188.42"",""podIP"":""172.17.0.5"",""startTime"":""2017-09-18T10:03:51Z"",""containerStatuses"":[{""name"":""nginx"",""state"":{""running"":{""startedAt"":""2017-10-12T07:09:20Z""}},""lastState"":{""terminated"":{""exitCode"":0,""reason"":""Completed"",""startedAt"":""2017-10-10T21:35:51Z"",""finishedAt"":""2017-10-12T07:07:37Z"",""containerID"":""docker://94df3f3965807421ad6dc76618e00b76cb15d024919c4946f3eb46a92659c62a""}},""ready"":true,""restartCount"":7,""image"":""nginx:latest"",""imageID"":""docker-pullable://nginx@sha256:004ac1d5e791e705f12a17c80d7bb1e8f7f01aa7dca7deee6e65a03465392072"",""containerID"":""docker://fa11bdd48c9b7d3a6c4c3f9b6d7319743c3455ab8d00c57d59c083b319b88194""}],""qosClass"":""BestEffort""}}]}";

            var namespaceName = "gerd";
            var pods          = new List <Pod>();

            // Act
            using (var server = new MockK8sApiServer(mockResponse: k8sMockResponse))
            {
                var config = new KubernetesClientConfiguration {
                    Host = server.Uri.ToString()
                };
                K8sClient.Connect(config);
                pods = await K8sClient.ListNamesapcePodsAsync(namespaceName);
            }

            // Assert
            Assert.Equal(2, pods.Count);
            Assert.Equal("nginx-1493591563-xb2v4", pods[0].Name);
            Assert.Equal("Running", pods[0].Status);
            Assert.Equal("nginx-1493591564-xb2v4", pods[1].Name);
            Assert.Equal("Running", pods[1].Status);
        }
Esempio n. 2
0
        public async void ListNamespaces_Basic_Works()
        {
            // Arrange
            var k8sMockResponse = @"{""kind"":""NamespaceList"",""apiVersion"":""v1"",""metadata"":{""selfLink"":""/api/v1/namespaces"",""resourceVersion"":""1762810""},""items"":[{""metadata"":{""name"":""gerd"",""selfLink"":""/api/v1/namespaces/gerd"",""uid"":""ac1abb94-9c58-11e7-aaf5-00155d744505"",""resourceVersion"":""1737928"",""creationTimestamp"":""2017-09-18T10:03:51Z"",""labels"":{""name"":""gerd""}},""status"":{""phase"":""Active""}}]}";

            var namespaces = new List <Namespace>();

            // Act
            using (var server = new MockK8sApiServer(mockResponse: k8sMockResponse))
            {
                var config = new KubernetesClientConfiguration {
                    Host = server.Uri.ToString()
                };
                K8sClient.Connect(config);
                namespaces = await K8sClient.ListNamesapcesAsync();
            }

            // Assert
            Assert.Single(namespaces);
            Assert.Equal("gerd", namespaces[0].Name);
            Assert.Equal("Active", namespaces[0].Status);
        }