ShortURL: Graduate api v1alpha1 to v1beta1 (#113597)

This commit is contained in:
Ezequiel Victorero
2025-11-10 07:29:33 -03:00
committed by GitHub
parent 834ff1be3c
commit cd91f858e6
34 changed files with 158 additions and 213 deletions
@@ -1,4 +1,4 @@
package v1alpha1
package v1beta1
import "k8s.io/apimachinery/pkg/runtime/schema"
@@ -6,7 +6,7 @@ const (
// APIGroup is the API group used by all kinds in this package
APIGroup = "shorturl.grafana.app"
// APIVersion is the API version used by all kinds in this package
APIVersion = "v1alpha1"
APIVersion = "v1beta1"
)
var (
@@ -1,4 +1,4 @@
package v1alpha1
package v1beta1
import (
"context"
@@ -2,7 +2,7 @@
// Code generated by grafana-app-sdk. DO NOT EDIT.
//
package v1alpha1
package v1beta1
import (
"encoding/json"
@@ -1,6 +1,6 @@
// Code generated - EDITING IS FUTILE. DO NOT EDIT.
package v1alpha1
package v1beta1
// +k8s:openapi-gen=true
type GetGoto struct {
@@ -1,6 +1,6 @@
// Code generated - EDITING IS FUTILE. DO NOT EDIT.
package v1alpha1
package v1beta1
import (
time "time"
@@ -2,7 +2,7 @@
// Code generated by grafana-app-sdk. DO NOT EDIT.
//
package v1alpha1
package v1beta1
import (
"fmt"
@@ -2,7 +2,7 @@
// Code generated by grafana-app-sdk. DO NOT EDIT.
//
package v1alpha1
package v1beta1
import (
"github.com/grafana/grafana-app-sdk/resource"
@@ -10,7 +10,7 @@ import (
// schema is unexported to prevent accidental overwrites
var (
schemaShortURL = resource.NewSimpleSchema("shorturl.grafana.app", "v1alpha1", &ShortURL{}, &ShortURLList{}, resource.WithKind("ShortURL"),
schemaShortURL = resource.NewSimpleSchema("shorturl.grafana.app", "v1beta1", &ShortURL{}, &ShortURLList{}, resource.WithKind("ShortURL"),
resource.WithPlural("shorturls"), resource.WithScope(resource.NamespacedScope))
kindShortURL = resource.Kind{
Schema: schemaShortURL,
@@ -1,6 +1,6 @@
// Code generated - EDITING IS FUTILE. DO NOT EDIT.
package v1alpha1
package v1beta1
// +k8s:openapi-gen=true
type ShortURLSpec struct {
@@ -1,6 +1,6 @@
// Code generated - EDITING IS FUTILE. DO NOT EDIT.
package v1alpha1
package v1beta1
// +k8s:openapi-gen=true
type ShortURLstatusOperatorState struct {
+9 -9
View File
@@ -16,22 +16,22 @@ import (
"k8s.io/kube-openapi/pkg/spec3"
"k8s.io/kube-openapi/pkg/validation/spec"
v1alpha1 "github.com/grafana/grafana/apps/shorturl/pkg/apis/shorturl/v1alpha1"
v1beta1 "github.com/grafana/grafana/apps/shorturl/pkg/apis/shorturl/v1beta1"
)
var (
rawSchemaShortURLv1alpha1 = []byte(`{"OperatorState":{"additionalProperties":false,"properties":{"descriptiveState":{"description":"descriptiveState is an optional more descriptive state field which has no requirements on format","type":"string"},"details":{"additionalProperties":{"additionalProperties":{},"type":"object"},"description":"details contains any extra information that is operator-specific","type":"object"},"lastEvaluation":{"description":"lastEvaluation is the ResourceVersion last evaluated","type":"string"},"state":{"description":"state describes the state of the lastEvaluation.\nIt is limited to three possible states for machine evaluation.","enum":["success","in_progress","failed"],"type":"string"}},"required":["lastEvaluation","state"],"type":"object"},"ShortURL":{"properties":{"spec":{"$ref":"#/components/schemas/spec"},"status":{"$ref":"#/components/schemas/status"}},"required":["spec"]},"spec":{"additionalProperties":false,"properties":{"path":{"description":"The original path to where the short url is linking too e.g. https://localhost:3000/eer8i1kictngga/new-dashboard-with-lib-panel","type":"string"}},"required":["path"],"type":"object"},"status":{"additionalProperties":false,"properties":{"additionalFields":{"additionalProperties":{"additionalProperties":{},"type":"object"},"description":"additionalFields is reserved for future use","type":"object"},"lastSeenAt":{"description":"The last time the short URL was used, 0 is the initial value","type":"integer"},"operatorStates":{"additionalProperties":{"$ref":"#/components/schemas/OperatorState"},"description":"operatorStates is a map of operator ID to operator state evaluations.\nAny operator which consumes this kind SHOULD add its state evaluation information to this field.","type":"object"}},"required":["lastSeenAt"],"type":"object"}}`)
versionSchemaShortURLv1alpha1 app.VersionSchema
_ = json.Unmarshal(rawSchemaShortURLv1alpha1, &versionSchemaShortURLv1alpha1)
rawSchemaShortURLv1beta1 = []byte(`{"OperatorState":{"additionalProperties":false,"properties":{"descriptiveState":{"description":"descriptiveState is an optional more descriptive state field which has no requirements on format","type":"string"},"details":{"additionalProperties":{"additionalProperties":{},"type":"object"},"description":"details contains any extra information that is operator-specific","type":"object"},"lastEvaluation":{"description":"lastEvaluation is the ResourceVersion last evaluated","type":"string"},"state":{"description":"state describes the state of the lastEvaluation.\nIt is limited to three possible states for machine evaluation.","enum":["success","in_progress","failed"],"type":"string"}},"required":["lastEvaluation","state"],"type":"object"},"ShortURL":{"properties":{"spec":{"$ref":"#/components/schemas/spec"},"status":{"$ref":"#/components/schemas/status"}},"required":["spec"]},"spec":{"additionalProperties":false,"properties":{"path":{"description":"The original path to where the short url is linking too e.g. https://localhost:3000/eer8i1kictngga/new-dashboard-with-lib-panel","type":"string"}},"required":["path"],"type":"object"},"status":{"additionalProperties":false,"properties":{"additionalFields":{"additionalProperties":{"additionalProperties":{},"type":"object"},"description":"additionalFields is reserved for future use","type":"object"},"lastSeenAt":{"description":"The last time the short URL was used, 0 is the initial value","type":"integer"},"operatorStates":{"additionalProperties":{"$ref":"#/components/schemas/OperatorState"},"description":"operatorStates is a map of operator ID to operator state evaluations.\nAny operator which consumes this kind SHOULD add its state evaluation information to this field.","type":"object"}},"required":["lastSeenAt"],"type":"object"}}`)
versionSchemaShortURLv1beta1 app.VersionSchema
_ = json.Unmarshal(rawSchemaShortURLv1beta1, &versionSchemaShortURLv1beta1)
)
var appManifestData = app.ManifestData{
AppName: "shorturl",
Group: "shorturl.grafana.app",
PreferredVersion: "v1alpha1",
PreferredVersion: "v1beta1",
Versions: []app.ManifestVersion{
{
Name: "v1alpha1",
Name: "v1beta1",
Served: true,
Kinds: []app.ManifestVersionKind{
{
@@ -47,7 +47,7 @@ var appManifestData = app.ManifestData{
},
},
},
Schema: &versionSchemaShortURLv1alpha1,
Schema: &versionSchemaShortURLv1beta1,
Routes: map[string]spec3.PathProps{
"/goto": {
Get: &spec3.Operation{
@@ -106,7 +106,7 @@ func RemoteManifest() app.Manifest {
}
var kindVersionToGoType = map[string]resource.Kind{
"ShortURL/v1alpha1": v1alpha1.ShortURLKind(),
"ShortURL/v1beta1": v1beta1.ShortURLKind(),
}
// ManifestGoTypeAssociator returns the associated resource.Kind instance for a given Kind and Version, if one exists.
@@ -117,7 +117,7 @@ func ManifestGoTypeAssociator(kind, version string) (goType resource.Kind, exist
}
var customRouteToGoResponseType = map[string]any{
"v1alpha1|ShortURL|goto|GET": v1alpha1.GetGoto{},
"v1beta1|ShortURL|goto|GET": v1beta1.GetGoto{},
}
// ManifestCustomRouteResponsesAssociator returns the associated response go type for a given kind, version, custom route path, and method, if one exists.
+9 -9
View File
@@ -18,7 +18,7 @@ import (
"github.com/grafana/grafana-app-sdk/operator"
"github.com/grafana/grafana-app-sdk/resource"
"github.com/grafana/grafana-app-sdk/simple"
shorturlv1alpha1 "github.com/grafana/grafana/apps/shorturl/pkg/apis/shorturl/v1alpha1"
shorturlv1beta1 "github.com/grafana/grafana/apps/shorturl/pkg/apis/shorturl/v1beta1"
"github.com/grafana/grafana/pkg/apimachinery/identity"
)
@@ -31,11 +31,11 @@ var (
func New(cfg app.Config) (app.App, error) {
cfg.KubeConfig.APIPath = "apis"
tmp, err := k8s.NewClientRegistry(cfg.KubeConfig, k8s.DefaultClientConfig()).
ClientFor(shorturlv1alpha1.ShortURLKind())
ClientFor(shorturlv1beta1.ShortURLKind())
if err != nil {
return nil, fmt.Errorf("unable to create client")
}
client := shorturlv1alpha1.NewShortURLClient(tmp)
client := shorturlv1beta1.NewShortURLClient(tmp)
simpleConfig := simple.AppConfig{
Name: "shorturl",
@@ -49,11 +49,11 @@ func New(cfg app.Config) (app.App, error) {
},
ManagedKinds: []simple.AppManagedKind{
{
Kind: shorturlv1alpha1.ShortURLKind(),
Kind: shorturlv1beta1.ShortURLKind(),
Validator: &simple.Validator{
ValidateFunc: func(ctx context.Context, req *app.AdmissionRequest) error {
// Cast the incoming object to ShortURL for validation
shortURL, ok := req.Object.(*shorturlv1alpha1.ShortURL)
shortURL, ok := req.Object.(*shorturlv1beta1.ShortURL)
if !ok {
return fmt.Errorf("expected ShortURL object, got %T", req.Object)
}
@@ -105,7 +105,7 @@ func New(cfg app.Config) (app.App, error) {
url = url + "/" + info.Spec.Path
if req.URL.Query().Get("redirect") == "false" { // helpful for testing
return json.NewEncoder(w).Encode(shorturlv1alpha1.GetGoto{
return json.NewEncoder(w).Encode(shorturlv1beta1.GetGoto{
Url: url,
})
}
@@ -133,10 +133,10 @@ func New(cfg app.Config) (app.App, error) {
func GetKinds() map[schema.GroupVersion][]resource.Kind {
gv := schema.GroupVersion{
Group: shorturlv1alpha1.ShortURLKind().Group(),
Version: shorturlv1alpha1.ShortURLKind().Version(),
Group: shorturlv1beta1.ShortURLKind().Group(),
Version: shorturlv1beta1.ShortURLKind().Version(),
}
return map[schema.GroupVersion][]resource.Kind{
gv: {shorturlv1alpha1.ShortURLKind()},
gv: {shorturlv1beta1.ShortURLKind()},
}
}