Пример #1
0
        public async Task <V1Namespace> CreateV1NamespaceAsync(
            string v1NamespaceContent,
            CancellationToken cancellationToken = default
            )
        {
            if (string.IsNullOrEmpty(v1NamespaceContent))
            {
                throw new ArgumentNullException(nameof(v1NamespaceContent));
            }

            try {
                Log.Verbose("Loading k8s Namespace definition ...");
                var v1NamespaceDefinition = Yaml.LoadFromString <V1Namespace>(v1NamespaceContent);

                Log.Verbose($"Creating k8s Namespace: {v1NamespaceDefinition.Metadata.Name} ...");
                var v1Namespace = await _k8sClient
                                  .CreateNamespaceAsync(
                    v1NamespaceDefinition,
                    cancellationToken : cancellationToken
                    );

                Log.Verbose($"Created k8s Namespace: {v1Namespace.Metadata.Name}");

                return(v1Namespace);
            }
            catch (Exception ex) {
                Log.Error(ex, $"Failed to create k8s Namespace");
                throw;
            }
        }
Пример #2
0
        public async Task <V1Namespace> CreateIIoTNamespaceAsync()
        {
            try {
                Log.Verbose("Loading k8s Namespace definition ...");

                var iiotNamespaceDefinition = Yaml
                                              .LoadFromString <V1Namespace>(
                    Resources.IIoTK8SResources._00_industrial_iot_namespace
                    );

                if (null != _iiotNamespace)
                {
                    iiotNamespaceDefinition.Metadata.Name = _iiotNamespace;
                }

                Log.Verbose($"Creating k8s Namespace: {iiotNamespaceDefinition.Metadata.Name} ...");

                var iiotNamespace = await _k8sClient.CreateNamespaceAsync(iiotNamespaceDefinition);

                Log.Verbose($"Created k8s Namespace: {iiotNamespace.Metadata.Name}");

                return(iiotNamespace);
            }
            catch (Exception ex) {
                Log.Error(ex, $"Failed to create k8s Namespace");
                throw;
            }
        }
Пример #3
0
        public async Task CreateNamespace(string namespaceName, string roleName)
        {
            var ns = new V1Namespace
            {
                Metadata = new V1ObjectMeta
                {
                    Name        = namespaceName,
                    Annotations = new Dictionary <string, string> {
                        { "iam.amazonaws.com/permitted", roleName }
                    }
                }
            };

            try
            {
                await _client.CreateNamespaceAsync(ns);
            }
            catch (HttpOperationException e) when(e.Response.Content.Length != 0)
            {
                throw new Exception(
                          "Error occured while communicating with k8s:" + Environment.NewLine +
                          e.Response.Content
                          , e
                          );
            }
        }
Пример #4
0
 public Task CreateNamespaceAsync(
     V1Namespace body,
     string pretty,
     CancellationToken cancellationToken = default(CancellationToken)
     )
 {
     return(_kubernetes.CreateNamespaceAsync(
                body,
                pretty,
                cancellationToken
                ));
 }
Пример #5
0
 private async Task CreateNamespaceAsync(V1Namespace @namespace)
 {
     try
     {
         await _client.CreateNamespaceAsync(@namespace);
     }
     catch (HttpOperationException e) when(e.Response.Content.Length != 0)
     {
         throw new Exception(
                   "Error occured while communicating with k8s:" + Environment.NewLine +
                   e.Response.Content
                   , e
                   );
     }
 }