예제 #1
0
            public SampleAppsFixture()
            {
                BuildNumber = Environment.GetEnvironmentVariable(BUILD_NUMBER_VAR) ?? Guid.NewGuid().ToString();
                BuildNumber = BuildNumber.Replace('.', '_'); // Dots are invalid in Kubernetes service names

                var storageKey = Environment.GetEnvironmentVariable(STORAGE_KEY_VAR);

                Console.WriteLine("Using storage key \"{0}...\" from environment variable \"{1}\"", storageKey.Substring(0, 4), STORAGE_KEY_VAR);

                FolderName = "SampleApps-" + BuildNumber;

                fileShare = CloudStorageAccount.Parse($"DefaultEndpointsProtocol=https;AccountName={STORAGE_ACCOUNT_NAME};AccountKey={storageKey};EndpointSuffix=core.windows.net")
                            .CreateCloudFileClient()
                            .GetShareReference(STORAGE_SHARE_NAME);

                UploadToFileShare(fileShare, FolderName);

                KubernetesClientConfiguration config;
                string kubeConfig = Environment.GetEnvironmentVariable(KUBECONFIG_VAR);

                if (string.IsNullOrEmpty(kubeConfig))
                {
                    config = KubernetesClientConfiguration.BuildConfigFromConfigFile();
                }
                else
                {
                    byte[] configByteArray = System.Text.Encoding.UTF8.GetBytes(kubeConfig);
                    using (var stream = new MemoryStream(configByteArray))
                    {
                        config = KubernetesClientConfiguration.BuildConfigFromConfigFile(stream);
                    }
                }
                Client = new Kubernetes(config);

                // Create a PV for our Azure File share and a corresponding claim if they don't already exist
                // If these fail, make sure that they don't already exist in the cluster: `kubectl delete -n default pvc,pv --all`
                storage      = Client.CreatePersistentVolume(Specs.BuildVolume.GetSpec(VOLUME_NAME, STORAGE_REQUESTED_CAPACITY, STORAGE_SHARE_NAME));
                storageClaim = Client.CreateNamespacedPersistentVolumeClaim(Specs.BuildVolumeClaim.GetSpec(STORAGE_REQUESTED_CAPACITY), NAMESPACE);
                Console.WriteLine("Created PersistentVolume and corresponding PersistentVolumeClaim");

                // Create the build pod
                var podSpec = Specs.BuildPod.GetSpec(BUILD_POD_NAME, VOLUME_NAME, storageClaim.Metadata.Name);

                BuildPod = k8sHelpers.CreatePodAndWait(Client, podSpec, NAMESPACE, k8sHelpers.IsPodRunning).Result;
                Console.WriteLine("Build pod is up & running");
            }