Ejemplo n.º 1
0
            public Task <ITriggerData> BindAsync(object value, ValueBindingContext context)
            {
                // TODO: Perfrom any required conversions on the value
                KubernetesTriggerValue triggerValue = value as KubernetesTriggerValue;
                IValueBinder           valueBinder  = new KubernetesValueBinder(_parameter, triggerValue);

                return(Task.FromResult <ITriggerData>(new TriggerData(valueBinder, GetBindingData(triggerValue))));
            }
Ejemplo n.º 2
0
            private IReadOnlyDictionary <string, object> GetBindingData(KubernetesTriggerValue value)
            {
                Dictionary <string, object> bindingData = new Dictionary <string, object>(StringComparer.OrdinalIgnoreCase);

                bindingData.Add("KubernetesTrigger", value);
                // TOD: Add any additional binding data
                return(bindingData);
            }
Ejemplo n.º 3
0
            private async void OnTimer(object sender, System.Timers.ElapsedEventArgs e)
            {
                // Call Kubernetes REST API

                client.DefaultRequestHeaders.Clear();
                client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", this._attribute.Token);
                var response = await client.GetAsync("/api/v1/namespaces/default/pods");

                var result = await response.Content.ReadAsStringAsync();

                var resultOject = JsonConvert.DeserializeObject <Rootobject>(result);

                bool hasWrongPod = false;

                foreach (var item in resultOject.items)
                {
                    var ts = DateTime.UtcNow - item.status.startTime;
                    if ("Pending" == item.status.phase || ts.TotalMinutes > 5)
                    {
                        Console.WriteLine("**** Wrong Pod Detected ****");
                        hasWrongPod = true;
                    }
                    Console.WriteLine($"Pod: {item.metadata.name}");
                    Console.WriteLine($"Status: {item.status.phase}");
                    Console.WriteLine($"Started {ts.TotalMinutes} min before");
                }
                // Get to know if it is wrong Pod
                if (hasWrongPod)
                {
                    // Trigger the function.
                    var triggerValue = new KubernetesTriggerValue();
                    triggerValue.Result = result;
                    TriggeredFunctionData input = new TriggeredFunctionData
                    {
                        TriggerValue = triggerValue
                    };
                    await _executor.TryExecuteAsync(input, CancellationToken.None);
                }
            }
Ejemplo n.º 4
0
 public KubernetesValueBinder(ParameterInfo parameter, KubernetesTriggerValue value) : base(parameter.ParameterType)
 {
     _value = value;
 }