stripe / skycfg

Skycfg is an extension library for the Starlark language that adds support for constructing Protocol Buffer messages.
Apache License 2.0
648 stars 54 forks source link

How to work with k8s CRDs #70

Open leoluk opened 4 years ago

leoluk commented 4 years ago

What's the right approach dealing with k8s CRDs in skycfg? Those are becoming increasingly common. cuelang solves this by having an intermediary typing language that can consume both Go structs and protobufs, such that it can validate either.

As far as I can tell, CRDs are only specified as jsonapi schemas and no protobuf schemas are generated.

dilyevsky commented 4 years ago

I haven’t tested it yet but If CRD provides openapi definitions you can generate proto representations using google gnostic tool - https://github.com/googleapis/gnostic-go-generator/blob/master/README.md

After that it should work the same way.

On Sat, Jan 4, 2020 at 5:34 PM Leopold Schabel notifications@github.com wrote:

What's the right approach dealing with k8s CRDs in skycfg? Those are becoming increasingly common. cuelang solves this by having an intermediary typing language that can consume both Go structs and protobufs, such that it can validate either.

As far as I can tell, CRDs are only specified as jsonapi schemas and no protobuf schemas are generated.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/stripe/skycfg/issues/70?email_source=notifications&email_token=AAF3KADN6URXUW5NFQSJ47TQ4CM7ZA5CNFSM4KCWKZDKYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4IEAPXRA, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAF3KAEPB7V6QK5HB4K4YKTQ4CM7ZANCNFSM4KCWKZDA .

leoluk commented 4 years ago

How would one use struct objects for untyped objects?

On https://skycfg.fun, this does not work:

def main(ctx):
  return [struct()]
`main' returned something that's not a protobuf (a struct)
dilyevsky commented 4 years ago

You can’t. Main needs to return proto wrapped into skyProtoMessage (there’s a helper for that).

On Sat, Jan 4, 2020 at 7:27 PM Leopold Schabel notifications@github.com wrote:

How would one use struct objects for untyped objects?

On https://skycfg.fun, this does not work:

def main(ctx): return [struct()]

`main' returned something that's not a protobuf (a struct)

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/stripe/skycfg/issues/70?email_source=notifications&email_token=AAF3KAACBD4R6CGBARTUFADQ4C2FZA5CNFSM4KCWKZDKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEIC3FEQ#issuecomment-570798738, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAF3KACKSLUWRNMYZ3BAQVLQ4C2FZANCNFSM4KCWKZDA .

jmillikin-stripe commented 4 years ago

Do you know what Protobuf type Kubernetes is expecting to receive for a CRD? If it's something like google.protobuf.Struct then you can construct those directly in Skycfg using normal idioms.

leoluk commented 4 years ago

It appears that the k8s protobuf API does not support CRDs at all

dilyevsky commented 4 years ago

Correct, you have render them as json. Maybe that’ll change when go proto v2 is out

On Mon, Jan 6, 2020 at 4:28 PM Leopold Schabel notifications@github.com wrote:

It appears that the k8s protobuf API does not support CRDs at all

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/stripe/skycfg/issues/70?email_source=notifications&email_token=AAF3KAF5HYLJN7GF3ORMCG3Q4MWYBA5CNFSM4KCWKZDKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEIFOALQ#issuecomment-571138094, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAF3KACWOPQBB4WCJV7IBBDQ4MWYBANCNFSM4KCWKZDA .