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

API Server Poc #231

Draft
wants to merge 50 commits into
base: main
Choose a base branch
from
Draft

API Server Poc #231

wants to merge 50 commits into from

Conversation

toddtreece
Copy link
Member

No description provided.

IfSentient and others added 30 commits February 9, 2024 11:50
…nterfaces, introduce Kinds (#200)

This PR supersedes #182
and is the first move toward the actual implementation of the ideas
present in that PR. Reviewers of
#182 have also been added
to this PR. *EDIT: I am unable to add some reviewers to this PR for
unexplained GitHub reasons*

This PR is a pull into a branch which is not main, as there will be
several PRs to get this into a working (compiling) shape, then that
branch will be pulled into main. All the work has been done to get this
into a working shape already, but the PR for that would be far too
large, so it is being split into these component PRs, to allow for
reviews and comments of each part of the design/implementation process.
This PR is _just_ the `resource` package, which introduces:
* Changes to the `Object` interface to make it a superset of the
kubernetes `runtime.Object`, `metav1.Object`, and `schema.ObjectKind`,
along with additional methods.
* Changes to the `ListObject` interface to also make it a superset of
`runtime.Object`, `schema.ObjectKind`, and `metav1.ListInterface`
* Removal of the Simple and Store objects in favor of a few basic
`Object` implementations: `UntypedObject`, which contains unstructured
spec and subresource data; `TypedSpecObject`, which contains typed spec
data, `TypedSpecStatusObject`, which contains typed spec and status
data; and `TypedObject`, which contains typed spec data and a typed
catalog of subresources.
* Since the `Object` interface no longer has the `Unmarshal` method,
introduce a `Codec` interface for reading/writing `Object` interfaces,
and a `Kind` struct type which unifies a `Schema` and one or more
`Codec`s based on the kind encoding. Anything which needs to read/write
bytes (`ClientRegistry`, and things which use it) now accept the `Kind`
as a parameter instead of `Schema`.
* ~Deprecation of `Schema` and its associated implementations and groups
in favor of `Kind`, which is `Schema` + an encoder and decoder for the
object.~
* ~Simple implementations of `Kind`: `TypedKind` and `UntypedKind`~
* Updates to the various stores to deal with these changes

There are a few open questions for reviewers noted in `TODO` comments,
namely around whether we need certain methods, or if certain method
signatures should be expanded upon. Other feedback is more than welcome.

---------

Co-authored-by: Igor Suleymanov <[email protected]>
Implement the changes to the `resource` package in all other packages.
This PR does _not_ include updates to codegen, this will be a subsequent
PR.

A final PR will be made after codegen changes with any fixes that come
up in more extensive local kubernetes testing.
This PR updates code generation to comply with the new `resource.Object`
interface, and introduce `resource.Kind` and `resource.Codec`. *There
are a few substantive changes to the generated code*:
* `ExtraFields` has been removed _entirely_ from generated metadata. It
is no longer used, as all kubernetes fields are now exposed directly
from the `Object.ObjectMeta` (or associated `Object.GetX`/`Object.SetX`
functions)
* `Object.Metadata` has been changed to `Object.ObjectMeta`, and is now
a kubernetes `metav1.ObjectMeta` object, containing _only_ kubernetes
metadata. _Custom_ metadata fields are now stored only in Annotations,
but can be retrieved/set with `GetX`/`SetX` generated methods on
`Object`.
* A new file named `x_codec_gen.go` is now generated, which has the
marshal/unmarshal logic for JSON. This file will be different if you are
using CUE- vs Thema-format kinds. Parsing thema-format kinds still uses
lineage binding, but some of the logic that formerly lived in
grafana-app-sdk/k8s to reformat metadata is now in the generated codec.
This should be non-impacting to usage, but something to note (the
unmarshal logic has changed, but should be transparent).

Full codegen changes are visible form the diffs on the
`golden_generated` files.
Update tutorial based on changes to Object interface and codegen.
Final miscellaneous fixes for linter, and a few bugs discovered when
doing more thorough testing in local kubernetes (main one was the
annotation prefix not being used in generated code).

After this PR, I will be creating a PR to merge the
`kind-object-refactor` branch into `main`.
Bumps the all group with 1 update:
[github.com/prometheus/client_golang](https://github.com/prometheus/client_golang).

Updates `github.com/prometheus/client_golang` from 1.18.0 to 1.19.0
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a
href="https://github.com/prometheus/client_golang/releases">github.com/prometheus/client_golang's
releases</a>.</em></p>
<blockquote>
<h2>v1.19.0</h2>
<h2>What's Changed</h2>
<p>The module <code>prometheus/common v0.48.0</code> introduced a bug
when used together with client_golang. If your project uses
client_golang and you want to use <code>prometheus/common v0.48.0</code>
or higher, please update client_golang to v1.19.0.</p>
<ul>
<li>[CHANGE] Minimum required go version is now 1.20 (we also test
client_golang against new 1.22 version). <a
href="https://redirect.github.com/prometheus/client_golang/issues/1445">#1445</a>
<a
href="https://redirect.github.com/prometheus/client_golang/issues/1449">#1449</a></li>
<li>[FEATURE] collectors: Add version collector. <a
href="https://redirect.github.com/prometheus/client_golang/issues/1422">#1422</a>
<a
href="https://redirect.github.com/prometheus/client_golang/issues/1427">#1427</a></li>
</ul>
<h2>New Contributors</h2>
<ul>
<li><a href="https://github.com/michurin"><code>@​michurin</code></a>
made their first contribution in <a
href="https://redirect.github.com/prometheus/client_golang/pull/1423">prometheus/client_golang#1423</a></li>
<li><a href="https://github.com/kavu"><code>@​kavu</code></a> made their
first contribution in <a
href="https://redirect.github.com/prometheus/client_golang/pull/1445">prometheus/client_golang#1445</a></li>
<li><a href="https://github.com/ywwg"><code>@​ywwg</code></a> made their
first contribution in <a
href="https://redirect.github.com/prometheus/client_golang/pull/1448">prometheus/client_golang#1448</a></li>
</ul>
<p><strong>Full Changelog</strong>: <a
href="https://github.com/prometheus/client_golang/compare/v1.18.0...v1.19.0">https://github.com/prometheus/client_golang/compare/v1.18.0...v1.19.0</a></p>
</blockquote>
</details>
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a
href="https://github.com/prometheus/client_golang/blob/v1.19.0/CHANGELOG.md">github.com/prometheus/client_golang's
changelog</a>.</em></p>
<blockquote>
<h2>1.19.0 / 2023-02-27</h2>
<p>The module <code>prometheus/common v0.48.0</code> introduced a bug
when used together with client_golang. If your project uses
client_golang and you want to use <code>prometheus/common v0.48.0</code>
or higher, please update client_golang to v1.19.0.</p>
<ul>
<li>[CHANGE] Minimum required go version is now 1.20 (we also test
client_golang against new 1.22 version). <a
href="https://redirect.github.com/prometheus/client_golang/issues/1445">#1445</a>
<a
href="https://redirect.github.com/prometheus/client_golang/issues/1449">#1449</a></li>
<li>[FEATURE] collectors: Add version collector. <a
href="https://redirect.github.com/prometheus/client_golang/issues/1422">#1422</a>
<a
href="https://redirect.github.com/prometheus/client_golang/issues/1427">#1427</a></li>
</ul>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="https://github.com/prometheus/client_golang/commit/77d4003c72f054ac435df1223deac17b1f8858ea"><code>77d4003</code></a>
Add 1.19.0 changelog (<a
href="https://redirect.github.com/prometheus/client_golang/issues/1451">#1451</a>)</li>
<li><a
href="https://github.com/prometheus/client_golang/commit/14259fa70cfb69f1262f69fdfe58ed5e6318d441"><code>14259fa</code></a>
Merge pull request <a
href="https://redirect.github.com/prometheus/client_golang/issues/1448">#1448</a>
from ywwg/owilliams/content-negotiation</li>
<li><a
href="https://github.com/prometheus/client_golang/commit/6d039205b8decc22868f43b0bd0da01b376a36aa"><code>6d03920</code></a>
deps: bump prometheus/common version</li>
<li><a
href="https://github.com/prometheus/client_golang/commit/353395b3b67b2bee0a219950bf5570779d74a392"><code>353395b</code></a>
Remove support for go 1.19 (<a
href="https://redirect.github.com/prometheus/client_golang/issues/1449">#1449</a>)</li>
<li><a
href="https://github.com/prometheus/client_golang/commit/9dd5d2a64af1e9bd0cbff0516ded6e51d25209bf"><code>9dd5d2a</code></a>
Merge pull request <a
href="https://redirect.github.com/prometheus/client_golang/issues/1445">#1445</a>
from kavu/add_go122_metrics_test</li>
<li><a
href="https://github.com/prometheus/client_golang/commit/c906a5e91a4604bd55fb8e26a54b5ba64a81c678"><code>c906a5e</code></a>
Add support for Go 1.22</li>
<li><a
href="https://github.com/prometheus/client_golang/commit/7ac90362b02729a65109b33d172bafb65d7dab50"><code>7ac9036</code></a>
Merge pull request <a
href="https://redirect.github.com/prometheus/client_golang/issues/1440">#1440</a>
from prometheus/dependabot/github_actions/github-act...</li>
<li><a
href="https://github.com/prometheus/client_golang/commit/8c7e30ff0dae76cb87061a37bbccc6c8789196fa"><code>8c7e30f</code></a>
Merge pull request <a
href="https://redirect.github.com/prometheus/client_golang/issues/1441">#1441</a>
from prometheus/dependabot/go_modules/tutorial/whats...</li>
<li><a
href="https://github.com/prometheus/client_golang/commit/08769f8257358282749a5180c9dc845f6e065640"><code>08769f8</code></a>
Bump github.com/prometheus/common in /tutorial/whatsup</li>
<li><a
href="https://github.com/prometheus/client_golang/commit/83d5940383d55377072d10a70316a7e24c5bb47c"><code>83d5940</code></a>
Bump the github-actions group with 2 updates</li>
<li>Additional commits viewable in <a
href="https://github.com/prometheus/client_golang/compare/v1.18.0...v1.19.0">compare
view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=github.com/prometheus/client_golang&package-manager=go_modules&previous-version=1.18.0&new-version=1.19.0)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore <dependency name> major version` will close this
group update PR and stop Dependabot creating any more for the specific
dependency's major version (unless you unignore this specific
dependency's major version or upgrade to it yourself)
- `@dependabot ignore <dependency name> minor version` will close this
group update PR and stop Dependabot creating any more for the specific
dependency's minor version (unless you unignore this specific
dependency's minor version or upgrade to it yourself)
- `@dependabot ignore <dependency name>` will close this group update PR
and stop Dependabot creating any more for the specific dependency
(unless you unignore this specific dependency or upgrade to it yourself)
- `@dependabot unignore <dependency name>` will remove all of the ignore
conditions of the specified dependency
- `@dependabot unignore <dependency name> <ignore condition>` will
remove the ignore condition of the specified dependency and ignore
conditions


</details>

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
The scripts correctly declare that they expect bash (by using
`#!/usr/bin/env bash`), but the generated makefile is calling these
scripts as `sh local/scripts/...`, which basically discards the shebang
and assumes that `sh` is `bash`.

Remove `sh` from the Makefile to fix this.

Signed-off-by: Marcelo E. Magallon <[email protected]>
When using `grafana-app-sdk project init` files are being created with
the executable bit set in cases where it's not needed (e.g. some code,
makefiles, etc). Given how there are two different functions,
`writeFile` and `writeExecutableFile`, it's clear that this was not the
intention.

Modify `writeFile` so that it creates files with the read/write bits
set, but not the executuable one.

Modify both `writeFile` and `writeExecutableFile` so that the process'
umask is respected (i.e. pass 0666 instead of 0644).

Signed-off-by: Marcelo E. Magallon <[email protected]>
…ame, since generated code is now packaged by GroupVersion rather than KindVersion.
… moved some of the simple code into the apiserver package. Some inital work on subresource routes.
…st multi-version code. Added reconciler logic to the APIServer.
IfSentient and others added 5 commits March 20, 2024 10:11
Base automatically changed from kind-object-refactor to main March 28, 2024 12:51
for _, r := range g.Resources {
for gid, g := range groups {
for rid, _ := range g.Resources {
r := &groups[gid].Resources[rid]
Copy link
Member Author

@toddtreece toddtreece Apr 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@IfSentient the issue with multiple versions was the pointer in the range loop changing. making a new pointer fixed the issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants