Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reload on configmap change not working #82

Open
msmaverick2018 opened this issue May 20, 2019 · 7 comments
Open

reload on configmap change not working #82

msmaverick2018 opened this issue May 20, 2019 · 7 comments

Comments

@msmaverick2018
Copy link

I tried setting it up in a demo asp.net core app, the configuration does not reload when the config map changes. Do you have any working samples for ASP.NET Core Web App

@tintoy
Copy link
Owner

tintoy commented May 20, 2019

Hi - does this sample work correctly for you?

https://github.com/tintoy/dotnet-kube-client/tree/develop/samples/ConfigFromConfigMap

I know it's not ASP.NET Core, but it'll at least tell me whether config-map reloads work for you at all (and we can go from there).

@tintoy
Copy link
Owner

tintoy commented May 20, 2019

BTW, if you want to see changes to config after the app is started, you need to inject IOptionsMonitor<MyOptions> not IOptions<MyOptions> (that one has caught me out before).

@tintoy
Copy link
Owner

tintoy commented May 20, 2019

BTW, here's the smallest example I could make:

public class Startup
{
    public Startup(IConfiguration configuration) => Configuration = configuration;

    public IConfiguration Configuration { get; }

    public void ConfigureServices(IServiceCollection services)
    {
        services.AddOptions();
        services.Configure<MyOptions>(Configuration);
    }

    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
    public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {
        app.Use(next => async context =>
        {
            MyOptions options = context.RequestServices.GetRequiredService<IOptionsMonitor<MyOptions>>().CurrentValue;

            await context.Response.WriteAsync(
                $"Foo: '{options.Foo}', Bar: '{options.Bar}'"
            );
        });
    }
}

public class MyOptions
{
    public string Foo { get; set; }
    public string Bar { get; set; }
}

public static class Program
{
    public static void Main(string[] args)
    {
        CreateHostBuilder(args).Build().Run();
    }

    public static IHostBuilder CreateHostBuilder(string[] args) =>
        Host.CreateDefaultBuilder(args)
            .ConfigureAppConfiguration(config =>
            {
                KubeClientOptions clientOptions = K8sConfig.Load().ToKubeClientOptions(
                    defaultKubeNamespace: "default"
                );

                config.AddKubeConfigMap(clientOptions, "my-config-map", reloadOnChange: true);
            })
            .ConfigureWebHostDefaults(webBuilder =>
            {
                webBuilder.UseStartup<Startup>();
            });
}

@msmaverick2018
Copy link
Author

Thanks for responding, I have tried it an ASP.NET Core application using IOptionsMonitor but i am still not seeing the update. I have read your blog too. Following is the git repo for my attempt:
C# Code: https://github.com/msmaverick2018/knative-repo/tree/master/AspnetCoreApp
Kubernetes stuff: https://github.com/msmaverick2018/knative-repo/tree/master/kubernetes

Not sure if i am missing something obvious. Thanks for your help in advance.

@tintoy
Copy link
Owner

tintoy commented May 21, 2019

Just out of curiosity, if you try the example code I posted above, does that work for you?

@jkdey
Copy link

jkdey commented Nov 11, 2019

Running into a similar issue where reloadOnChange appears to stop working after a while. I think it may be related to the fact that watches timeout after a while. Does the client retry on watch expiration?

kubernetes/kubernetes#42552
kubernetes-client/java#266

protected IObservable<string> ObserveLines(HttpRequest request, string operationDescription, int bufferSize = DefaultStreamingBufferSize)

@tintoy
Copy link
Owner

tintoy commented Nov 12, 2019

No - I don’t think we attempt to retry. I guess we could implement that if I can figure out exactly what a timeout response looks like though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants