# Introducing Swiftkube

**URL:** <https://forums.swift.org/t/introducing-swiftkube/42035>\
**Category:** Related Projects\
**Tags:** server, swift-nio, kubernetes\
**Created:** [November 15, 2020, 8:36pm UTC](https://forums.swift.org/t/introducing-swiftkube/42035 "2020-11-15T20:36:33Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![iabudiab](https://avatars.discourse-cdn.com/v4/letter/i/f0a364/32.png) [@iabudiab](https://forums.swift.org/u/iabudiab)\
**Post date:** [November 15, 2020, 8:36pm UTC](https://forums.swift.org/t/introducing-swiftkube/42035/1 "2020-11-15T20:36:33Z")

</div>

[Swiftkube](https://github.com/swiftkube) is Swift tooling for Kubernetes.

## Motivation

This is a project I've been working on for some time now, which went through several iterations until I got into the current shape and form.

Swift as a language is among the most pleasant to use and it's seen many advancements in many areas, including the server-side. What's been lacking, IMHO, is more work put into the whole cloud native landscape, especially Kubernetes.

I hope Swiftkube will contribute towards gapping this bridge.

## Current State

The project currently consists of two packages and an examples repository

- [SwiftkubeModel](https://github.com/swiftkube/model): which is the complete Kubernetes model for v1.18.9
- [SwiftkubeClient](https://github.com/swiftkube/client): a SwiftNIO based client
- [SwiftkubeExamples](https://github.com/swiftkube/examples): some concrete examples for what's currently possible with Swiftkube

Furthermore, I am working on two other packages, wich I'll push once they're in a more-or-less presentable state:

- Swiftkube Mock Server: a programmatically mockable Kuberentes API server, that can be used either standalone or as an embedded dependency. This one will be used for the end-2-end tests for the Client implementation.
- A proof of concept Service Discovery implementation on Kubernetes for the newly introduced [swift-service-discovery](https://github.com/apple/swift-service-discovery)

## Some Background / Further Info

The model package is not generated by the OpenAPI Generator, instead I wrote a custom generator in Swift, which I will also open source after some polishing.

**Why not OpenAPI?**

- [OpenAPI Generator for Swift](https://github.com/OpenAPITools/openapi-generator/pull/4086) doesn't generate SwiftNIO/AsyncHTTPClient code
- And [OpenAPI Generator + SwiftNIO](https://github.com/OpenAPITools/openapi-generator/issues/4957) is open since January and there seems to be no progress
- Client code generated by OpenAPI Tools would probably fail to decode K8s objects, that include a `meta.v1.MicroTime` field (ISO8601 with milliseconds) e.g. or `core/v1/Event` or `coordination.k8s.io/v1/Lease`. _This is an assumption, which I haven't tested._
- And even the OpenAPI tooling could produce an AsyncHTTPClient-based client, the generated code is, IMHO, just not something I would want to use or would have fun using because of the very verbose models and client code, e.g. `AppsV1beta1Deployment` or `PolicyV1beta1PodSecurityPolicy`. Compare this to Swiftkube's `apps.v1.Deployment` and `policy.v1beta.PodSecurityPolicy`

The implementation is a little bit opionated and borrows some ideas from the [fabric8 Kubernetes Java Client](https://github.com/fabric8io/kubernetes-client), and others from [cdk8s](https://github.com/awslabs/cdk8s). Mainly because I find those really pleasant to work with.

Feedback and contributions are really welcome!

---

<div class="post-metadata">

**Author:** ![t089](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/t089/32/40449_2.png) [@t089](https://forums.swift.org/u/t089)\
**Post date:** [November 15, 2020, 11:05pm UTC](https://forums.swift.org/t/introducing-swiftkube/42035/2 "2020-11-15T23:05:13Z")

</div>

This is awesome. Thanks a lot for the hard work!

---

<div class="post-metadata">

**Author:** ![spprichard](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/spprichard/32/22828_2.png) [@spprichard](https://forums.swift.org/u/spprichard)\
**Post date:** [November 17, 2020, 1:40pm UTC](https://forums.swift.org/t/introducing-swiftkube/42035/3 "2020-11-17T13:40:07Z")

</div>

This is awesome!

---

<div class="post-metadata">

**Author:** ![m0wfo](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/m0wfo/32/11024_2.png) [@m0wfo](https://forums.swift.org/u/m0wfo)\
**Post date:** [January 26, 2021, 1:42pm UTC](https://forums.swift.org/t/introducing-swiftkube/42035/4 "2021-01-26T13:42:04Z")

</div>

Hey @iabudiab, this is super cool- we needed Kubernetes service discovery pretty quickly so had to come up [with this](https://github.com/tuplestream/swift-k8s-service-discovery), which depends on AsyncHTTPClient directly, but we'd be open to using your swiftkubeclient, or if you also have a swift-service-discovery k8s impl, switching it out completely. It was something we needed internally but didn't really want to write & maintain. Something of a recurring theme with server-side swift ;)

---

<div class="post-metadata">

**Author:** ![iabudiab](https://avatars.discourse-cdn.com/v4/letter/i/f0a364/32.png) [@iabudiab](https://forums.swift.org/u/iabudiab)\
**Post date:** [January 26, 2021, 9:18pm UTC](https://forums.swift.org/t/introducing-swiftkube/42035/5 "2021-01-26T21:18:27Z")

</div>

Hey @m0wfo, glad you like it 😄  
I am working or rather experimenting with a service discovery implementation based on Swiftkube but don't have anything ready yet. I could make a MVP, based on your variant with Swiftkube and develop it further from there. Maybe I'll give it a go the next weekend. Will keep you posted 😉

---

<div class="post-metadata">

**Author:** ![iabudiab](https://avatars.discourse-cdn.com/v4/letter/i/f0a364/32.png) [@iabudiab](https://forums.swift.org/u/iabudiab)\
**Post date:** [February 13, 2021, 2:08pm UTC](https://forums.swift.org/t/introducing-swiftkube/42035/6 "2021-02-13T14:08:09Z")

</div>

@m0wfo Hey there 👋  
FYI I've just released the first version of service discovery based on Swiftkube:

> **[GitHub - swiftkube/servicediscovery: Swift Service Discovery implementation...](https://github.com/swiftkube/servicediscovery)**
>
> Swift Service Discovery implementation for Kubernetes on Swiftkube - GitHub - swiftkube/servicediscovery: Swift Service Discovery implementation for Kubernetes on Swiftkube

It took longer that anticipated, but I really wanted to implement the reconnect behaviour in the client first, which landend in v0.6.0

Feedback and contributions are always welcome.

---

<div class="post-metadata">

**Author:** ![m0wfo](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/m0wfo/32/11024_2.png) [@m0wfo](https://forums.swift.org/u/m0wfo)\
**Post date:** [February 13, 2021, 7:59pm UTC](https://forums.swift.org/t/introducing-swiftkube/42035/7 "2021-02-13T19:59:11Z")

</div>

@iabudiab very awesome, I will take a look!
