Files
NageshbansalandGitHub b7722f0f22 feat: introduce casting kind (#116)
### Summary                            

- Introduce a `kind` discriminator for Casting. Existing Casting without
a kind field keep working, empty kind defaults to `Installation`
- New `api/v1alpha1/installation/` subpackage with the Installation
Casting, Spec types and holds its own JSON schema from its Go type:
`installation/casting.schema.json`
- New Machinery interface in `api/v1alpha1/machinery.go` exposes
`Kind()` and `TrackableProperties()` so Dispatcher(Getv1alpha1 and
Forge/Cast/Gauge) work across any kind without knowing its concrete
type.
- A root casting.schema.json lists every per-Kind schema to supports
IDEs completion from one schema URL
- cmd/foundryctl gen schemas reads a list of types from schemaTargets.
Adding a kind means adding one entry.
  
Related: https://github.com/SigNoz/platform-pod/issues/1970
2026-05-16 17:40:03 +05:30

83 lines
1.8 KiB
Go

package installation
import (
"encoding/json"
"errors"
"fmt"
"github.com/swaggest/jsonschema-go"
"go.yaml.in/yaml/v3"
)
var _ yaml.Marshaler = (*MetaStoreKind)(nil)
var _ yaml.Unmarshaler = (*MetaStoreKind)(nil)
var _ json.Marshaler = (*MetaStoreKind)(nil)
var _ json.Unmarshaler = (*MetaStoreKind)(nil)
var _ fmt.Stringer = (*MetaStoreKind)(nil)
var _ jsonschema.Enum = (*MetaStoreKind)(nil)
var (
MetaStoreKindPostgres MetaStoreKind = MetaStoreKind{s: "postgres"}
MetaStoreKindSQLite MetaStoreKind = MetaStoreKind{s: "sqlite"}
)
type MetaStoreKind struct {
s string
}
func (kind MetaStoreKind) String() string {
return kind.s
}
func MetaStoreKinds() []MetaStoreKind {
return []MetaStoreKind{MetaStoreKindPostgres, MetaStoreKindSQLite}
}
func (kind MetaStoreKind) MarshalJSON() ([]byte, error) {
return json.Marshal(kind.String())
}
func (kind *MetaStoreKind) UnmarshalJSON(text []byte) error {
var str string
if err := json.Unmarshal(text, &str); err != nil {
return err
}
return kind.UnmarshalText([]byte(str))
}
func (kind *MetaStoreKind) UnmarshalText(text []byte) error {
for _, availableKind := range MetaStoreKinds() {
if availableKind.String() == string(text) {
*kind = availableKind
return nil
}
}
if text == nil {
*kind = MetaStoreKind{s: ""}
return nil
}
return errors.New("invalid meta store kind: " + string(text))
}
func (kind MetaStoreKind) MarshalText() ([]byte, error) {
return []byte(kind.String()), nil
}
func (kind *MetaStoreKind) UnmarshalYAML(node *yaml.Node) error {
return kind.UnmarshalText([]byte(node.Value))
}
func (kind MetaStoreKind) MarshalYAML() (any, error) {
return kind.String(), nil
}
func (kind MetaStoreKind) Enum() []any {
kinds := []any{}
for _, kind := range MetaStoreKinds() {
kinds = append(kinds, kind.String())
}
return kinds
}