コード例 #1
0
        public PodEventHandler(
            Kubernetes client,
            GenericChaosClient chaosClient,
            ArmClient armClient,
            string watchNamespace = ""
            )
        {
            Client      = client;
            ChaosClient = chaosClient;
            ARMClient   = armClient;
            Namespace   = watchNamespace;

            Logger = new LoggerConfiguration()
                     .MinimumLevel.Information()
                     .Enrich
                     .FromLogContext()
                     .WriteTo.Console(
                outputTemplate: "[{Timestamp:hh:mm:ss} {Level:u3}] {Message,-30:lj} {Properties:j}{NewLine}{Exception}",
                theme: AnsiConsoleTheme.Code
                )
                     .CreateLogger();

            PodChaosHandledPatchBody = new V1Patch(PodChaosHandledPatch, V1Patch.PatchType.MergePatch);
            PodChaosResumePatchBody  = new V1Patch(PodChaosResumePatch, V1Patch.PatchType.MergePatch);
        }
コード例 #2
0
        static async Task Program(Options options)
        {
            KubernetesClientConfiguration config;

            // Try to load kubeconfig file, if running locally,
            // otherwise try in cluster config (running in k8s container)
            try
            {
                config = KubernetesClientConfiguration.BuildConfigFromConfigFile();
            }
            catch (Exception)
            {
                config = KubernetesClientConfiguration.InClusterConfig();
            }

            var client      = new Kubernetes(config);
            var chaosClient = new GenericChaosClient(config);

            DotEnv.Load(options: new DotEnvOptions(envFilePaths: new[] { "/mnt/outputs/.env" }));
            var subscriptionId = Environment.GetEnvironmentVariable("AZURE_SUBSCRIPTION_ID");

            // Default to 'Azure SDK Developer Playground' subscription when testing locally outside of the stress cluster.
            subscriptionId = subscriptionId ?? "faa080af-c1d8-40ad-9cce-e1a450ca5b57";

            ArmClient armClient = new ArmClient(subscriptionId, new DefaultAzureCredential());

            var podEventHandler = new PodEventHandler(client, chaosClient, armClient, options.Namespace);

            var cts = new CancellationTokenSource();
            await podEventHandler.Watch(cts.Token);
        }