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

Generating CRDs needs a Kubernetes context #346

Closed
buehler opened this issue Jan 2, 2022 Discussed in #343 · 1 comment
Closed

Generating CRDs needs a Kubernetes context #346

buehler opened this issue Jan 2, 2022 Discussed in #343 · 1 comment
Labels
bug Something isn't working released

Comments

@buehler
Copy link
Owner

buehler commented Jan 2, 2022

Discussed in #343

Originally posted by jefflill December 29, 2021
This looks like a really cool library. We're looking at this for implementing operators for a nascent Kubernetes distribution: neonKUBE

One problem I'm having is actually building an operator that generates CRDs. The issue appears to be with dependency injection trying to construct a KubernetesClient instance when I don't have a current Kubernetes context specified in my .kube/config file.

I replicated this with your KubeOps.TestOperator by executing (without a current Kubernetes context) in the debugger with this command line:

generator crds --out config\crds --format Yaml

here's the exception:

Unhandled exception. System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
 ---> k8s.Exceptions.KubeConfigException: Cannot infer server host url either from context or masterUrl
   at k8s.KubernetesClientConfiguration.GetKubernetesClientConfiguration(String currentContext, String masterUrl, K8SConfiguration k8SConfig)
   at k8s.KubernetesClientConfiguration.BuildConfigFromConfigObject(K8SConfiguration k8SConfig, String currentContext, String masterUrl)
   at k8s.KubernetesClientConfiguration.BuildDefaultConfig()
   at DotnetKubernetesClient.KubernetesClient..ctor()
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
   at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitDisposeCache(ServiceCallSite transientCallSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.Resolve(ServiceCallSite callSite, ServiceProviderEngineScope scope)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.DynamicServiceProviderEngine.<>c__DisplayClass1_0.<RealizeService>b__0(ServiceProviderEngineScope scope)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngine.GetService(Type serviceType, ServiceProviderEngineScope serviceProviderEngineScope)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope.GetService(Type serviceType)
   at McMaster.Extensions.CommandLineUtils.CommandLineApplication.ServiceProvider.GetService(Type serviceType)
   at McMaster.Extensions.CommandLineUtils.CommandLineApplication.System.IServiceProvider.GetService(Type serviceType)
   at McMaster.Extensions.CommandLineUtils.Conventions.ConstructorInjectionConvention.FindMatchedConstructor[TModel](ConstructorInfo[] constructors, IServiceProvider services, Boolean throwIfNoParameterTypeRegistered)
   at McMaster.Extensions.CommandLineUtils.Conventions.ConstructorInjectionConvention.ApplyImpl[TModel](ConventionContext context)
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
   at McMaster.Extensions.CommandLineUtils.Conventions.ConstructorInjectionConvention.Apply(ConventionContext context)
   at McMaster.Extensions.CommandLineUtils.CommandLineApplication.Builder.McMaster.Extensions.CommandLineUtils.Conventions.IConventionBuilder.AddConvention(IConvention convention)
   at McMaster.Extensions.CommandLineUtils.ConventionBuilderExtensions.UseConstructorInjection(IConventionBuilder builder, IServiceProvider additionalServices)
   at KubeOps.Operator.HostExtensions.RunOperatorAsync(IHost host, String[] args) in C:\Temp\dotnet-operator-sdk\src\KubeOps\Operator\HostExtensions.cs:line 24
   at Program.<Main>$(String[] args) in C:\Temp\dotnet-operator-sdk\tests\KubeOps.TestOperator\Program.cs:line 10
   at Program.<Main>(String[] args)

It seems to me that constructing a KubernetesClient instance isn't really necessary for generating the CRDs. Is there a way to avoid this?

@buehler buehler added the bug Something isn't working label Jan 2, 2022
@buehler buehler closed this as completed in cde5ef8 Jan 2, 2022
@github-actions
Copy link

github-actions bot commented Jan 2, 2022

🎉 This issue has been resolved in version 6.1.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working released
Projects
None yet
Development

No branches or pull requests

1 participant