-
I'm trying to create a class that represents a basic CronJob, with some properties that will be defined in instances of the class. For these examples, I've boiled it down to just the In a Kubernetes My naive first attempt to do this failed:
with
Which makes sense due to lazy evaluation and name resolution. But how do I set I see on https://pkl-lang.org/main/current/language-reference/index.html#name-resolution that there is an
returns:
Extending the CronJob class seems to work with
But this still fails when it comes the more deeply nested
fails with:
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
Perhaps I'm missing an easier solution, but "renaming" the outer property with |
Beta Was this translation helpful? Give feedback.
-
Typically what I do here is to add a import "@k8s/api/batch/v1/CronJob.pkl"
class Job {
local self = this
name: String
function createResource(): CronJob = new {
metadata {
name = self.name
}
}
} By the way, the function here isn't providing any value. You can just make that a class Job {
local self = this
name: String
fixed resource: CronJob = new {
metadata {
name = self.name
}
}
} |
Beta Was this translation helpful? Give feedback.
-
For reference, if you use something like |
Beta Was this translation helpful? Give feedback.
Typically what I do here is to add a
local self = this
.By the way, the function here isn't providing any value. You can just make that a
fixed
property. This is a little nicer because the value gets cached. Methods currently get re-computed every time they are called; Pkl does not memoize methods.