Unable to use variables for Kubernetes container limits

Hi there,

When trying to use a variable for the resource limits for a Kubernetes container deployment, there’s a regex validation on the fields that prevents me from saving the configuration, as it tries to validate the variable name as an actual value.

The error message states the following:
All container memory resource limits must match the regular expression '^([+-]?[0-9.]+)([eEinumkKMGTP]*[-+]?[0-9]*)$', e.g. 129M, 123Mi, 1G, 1Gi.

We’re in need of these values to vary between environments.

Any help would be appreciated.

Thanks.

Hi,

This was an issue that was resolved in Octopus 2019.4.3.
If you upgrade you should be able to use variable expressions in the container limit fields.

We apologize for the inconvenience. If that doesn’t resolve the problem, or if you have any other queries, please don’t hesitate to reach out.

Hi Michael,

Thanks for the reply.

Yes, indeed we were on an older release. We’ve updated now to the LTS version, 2019.6.8.

While it isn’t complaining about using a variable in those fields anymore, I still can’t save the configuration. Only now, the error seems to have switched to a null dereference instead.

Object reference not set to an instance of an object.

I’ve looked in the console and the request directly in Chrome, but it doesn’t provide any further information other than the save request results in a 500 with the error message above. Again, trying to save without the variables will work just fine. I’ve tried recreating the step, in case there would be anything to gain from that, but it’s the same problem.

Do we need to upgrade further than the LTS version?

Thanks.

Oh no. I’ve attempted to replicate the problem on the same version, but I was able to successfully save the step when using variable references in the cpu and memory limit fields.

If the problem is still occurring, would you be able to send some screenshots of your configuration? And could you also check the Octopus server log, to see if an error is logged with more information?

Hi Michael,

Thanks for your continued assistance in this.

I’m not fully sure what you wanted screenshots of exactly, so I’ve taken a few that should illustrate the process.

We’ve currently got 2 variables we’d like to use for the memory request and limit of a container.

When trying to use those in the container config, like so
container-config

I can no longer save the configuration for the step
step-overview

Without the variables and using the hardcoded values of 700Mi and 1200Mi, it works fine. From the server logs, here’s the stacktrace for this error

2019-09-13 10:20:53.2827   1464     47 ERROR  Unhandled error on request: http://hostname:8080/api/Spaces-1/deploymentprocesses/deploymentprocess-Projects-262 7ab5b25669c24543a701f86e5419cbeb by <anonymous> : Object reference not set to an instance of an object.
System.NullReferenceException: Object reference not set to an instance of an object.
   at Octopus.Kubernetes.Resources.Deployment.ResourceRequirementsDetails.get_MemoryValid()
   at Octopus.Kubernetes.KubernetesValidation.<>c.<AddDeploymentValidationRule>b__0_398(Container c)
   at System.Linq.Enumerable.All[TSource](IEnumerable`1 source, Func`2 predicate)
   at Octopus.Kubernetes.KubernetesValidation.<>c.<AddDeploymentValidationRule>b__0_179(Deployment a)
   at FluentValidation.Validators.PredicateValidator.IsValid(PropertyValidatorContext context)
   at FluentValidation.Validators.PropertyValidator.Validate(PropertyValidatorContext context)
   at FluentValidation.Internal.PropertyRule.<Validate>d__59.MoveNext()
   at System.Linq.Enumerable.<SelectManyIterator>d__17`2.MoveNext()
   at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at FluentValidation.Results.ValidationResult..ctor(IEnumerable`1 failures)
   at FluentValidation.AbstractValidator`1.Validate(ValidationContext`1 context)
   at FluentValidation.Validators.ChildValidatorAdaptor.<>c.<Validate>b__10_0(ValidationContext ctx, IValidator v)
   at FluentValidation.Validators.ChildValidatorAdaptor.Validate(PropertyValidatorContext context)
   at FluentValidation.Internal.PropertyRule.<Validate>d__59.MoveNext()
   at System.Linq.Enumerable.<SelectManyIterator>d__17`2.MoveNext()
   at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at FluentValidation.Results.ValidationResult..ctor(IEnumerable`1 failures)
   at FluentValidation.AbstractValidator`1.Validate(ValidationContext`1 context)
   at FluentValidation.Validators.ChildCollectionValidatorAdaptor.<>c.<Validate>b__14_1(Tuple`2 tuple)
   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
   at System.Linq.Enumerable.<SelectManyIterator>d__17`2.MoveNext()
   at FluentValidation.Internal.PropertyRule.<Validate>d__59.MoveNext()
   at System.Linq.Enumerable.<SelectManyIterator>d__17`2.MoveNext()
   at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at FluentValidation.Results.ValidationResult..ctor(IEnumerable`1 failures)
   at FluentValidation.AbstractValidator`1.Validate(ValidationContext`1 context)
   at FluentValidation.Validators.ChildCollectionValidatorAdaptor.<>c.<Validate>b__14_1(Tuple`2 tuple)
   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
   at System.Linq.Enumerable.<SelectManyIterator>d__17`2.MoveNext()
   at FluentValidation.Internal.PropertyRule.<Validate>d__59.MoveNext()
   at System.Linq.Enumerable.<SelectManyIterator>d__17`2.MoveNext()
   at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at FluentValidation.Results.ValidationResult..ctor(IEnumerable`1 failures)
   at FluentValidation.AbstractValidator`1.Validate(ValidationContext`1 context)
   at Octopus.Server.Web.Api.Actions.DeploymentProcessUpdater.Update(DeploymentProcess model, DeploymentProcessResource resource)
   at Octopus.Server.Web.Api.Actions.DeploymentProcessUpdateAction.ExecuteRegistered(String id)
   at Octopus.Server.Web.Infrastructure.Api.Responder`1.Respond(TDescriptor options, NancyContext context)
   at System.Dynamic.UpdateDelegates.UpdateAndExecute3[T0,T1,T2,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2)
   at Octopus.Server.Web.Infrastructure.OctopusNancyModule.<>c__DisplayClass14_0.<get_Routes>b__1(Object o, CancellationToken x)
   at Nancy.Routing.Route`1.<Invoke>d__7.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Nancy.Routing.DefaultRouteInvoker.<Invoke>d__2.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Nancy.Routing.DefaultRequestDispatcher.<Dispatch>d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Nancy.NancyEngine.<InvokeRequestLifeCycle>d__22.MoveNext()

Let me know if there’s any more information that we can provide.

Thanks.

Thank you for the extra information. That allowed me to replicate the problem.

There was a glitch in the validation for that step, where if you entered memory requirements but left the cpu requirements blank, it was causing the error you are seeing.

We have committed a fix for the issue, and have backported it to the LTS branch. This will be available for download in the coming days.

We sincerely apologize for the fact you have hit two consecutive issues. Hopefully the sailing is smoother from now.

Please continue to reach out if we can help in any way.