Skip to content

Commit

Permalink
Add initial definitions for KeyValue store
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelattwood committed Dec 31, 2024
1 parent 17a0ada commit 857f6a7
Show file tree
Hide file tree
Showing 59 changed files with 1,320 additions and 50 deletions.
1 change: 1 addition & 0 deletions controllers/jetstream/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ func NewController(opt Options) *Controller {
if err != nil {
panic(err)
}
defer os.RemoveAll(cacheDir)

return &Controller{
ctx: opt.Ctx,
Expand Down
215 changes: 215 additions & 0 deletions deploy/crds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1013,3 +1013,218 @@ spec:
file:
description: Credentials file, generated with github.com/nats-io/nsc tool.
type: string
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: keyvalue.jetstream.nats.io
spec:
group: jetstream.nats.io
scope: Namespaced
names:
kind: KeyValue
singular: keyvalue
plural: keyvalues
shortNames:
- kv
versions:
- name: v1beta2
served: true
storage: true
subresources:
status: {}
schema:
openAPIV3Schema:
type: object
properties:
spec:
type: object
properties:
name:
description: A unique name for the Key/Value store.
type: string
description:
description: The description of the Key/Value store.
type: string
maxValueSize:
description: The maximum size of a value in bytes.
type: integer
history:
description: The number of historical values to keep per key.
type: integer
ttl:
description: The time expiry for keys.
type: string
maxBytes:
description: The maximum size of the Key/Value store in bytes.
type: int
storage:
description: The storage backend to use for the Key/Value store.
type: string
enum:
- file
- memory
replicas:
description: The number of replicas to keep for the Key/Value store in clustered JetStream.
type: integer
minimum: 1
maximum: 5
placement:
description: The Key/Value store placement via tags or cluster name.
type: object
properties:
cluster:
type: string
tags:
type: array
items:
type: string
republish:
description: Republish configuration for the Key/Value store.
type: object
properties:
destination:
type: string
description: Messages will be additionally published to this subject after store.
source:
type: string
description: Messages will be published from this subject to the destination subject.
mirror:
description: A Key/Value store mirror.
type: object
properties:
name:
type: string
optStartSeq:
type: integer
optStartTime:
description: Time format must be RFC3339.
type: string
filterSubject:
type: string
externalApiPrefix:
type: string
externalDeliverPrefix:
type: string
subjectTransforms:
description: List of subject transforms for this mirror.
type: array
items:
description: A subject transform pair.
type: object
properties:
source:
description: Source subject.
type: string
dest:
description: Destination subject.
type: string
compression:
description: Key/Value store compression.
type: string
enum:
- s2
- none
- ''
sources:
description: A Key/Value store's sources.
type: array
items:
type: object
properties:
name:
type: string
optStartSeq:
type: integer
optStartTime:
description: Time format must be RFC3339.
type: string
filterSubject:
type: string
externalApiPrefix:
type: string
externalDeliverPrefix:
type: string
subjectTransforms:
description: List of subject transforms for this mirror.
type: array
items:
description: A subject transform pair.
type: object
properties:
source:
description: Source subject.
type: string
dest:
description: Destination subject.
type: string
servers:
description: A list of servers for creating stream
type: array
items:
type: string
default: []
creds:
description: NATS user credentials for connecting to servers. Please make sure your controller has mounted the cerds on its path.
type: string
default: ''
nkey:
description: NATS user NKey for connecting to servers.
type: string
default: ''
tls:
description: A client's TLS certs and keys.
type: object
properties:
clientCert:
description: A client's cert filepath. Should be mounted.
type: string
clientKey:
description: A client's key filepath. Should be mounted.
type: string
rootCas:
description: A list of filepaths to CAs. Should be mounted.
type: array
items:
type: string
account:
description: Name of the account to which the Stream belongs.
type: string
pattern: '^[^.*>]*$'
preventDelete:
description: When true, the managed Stream will not be deleted when the resource is deleted
type: boolean
default: false
preventUpdate:
description: When true, the managed Stream will not be updated when the resource is updated
type: boolean
default: false
status:
type: object
properties:
observedGeneration:
type: integer
conditions:
type: array
items:
type: object
properties:
type:
type: string
status:
type: string
lastTransitionTime:
type: string
reason:
type: string
message:
type: string
additionalPrinterColumns:
- name: State
type: string
description: The current state of the Key/Value store.
jsonPath: .status.conditions[?(@.type == 'Ready')].reason
- name: Key/Value Store Name
type: string
description: The name of the Key/Value store.
jsonPath: .spec.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

55 changes: 55 additions & 0 deletions pkg/jetstream/apis/jetstream/v1beta2/keyvaluetypes.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package v1beta2

import (
k8smeta "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// Stream is a specification for a Stream resource
type KeyValue struct {
k8smeta.TypeMeta `json:",inline"`
k8smeta.ObjectMeta `json:"metadata,omitempty"`

Spec KeyValueSpec `json:"spec"`
Status Status `json:"status"`
}

func (s *KeyValue) GetSpec() interface{} {
return s.Spec
}

// StreamSpec is the spec for a Stream resource
type KeyValueSpec struct {
Account string `json:"account"`
Compression string `json:"compression"`
Creds string `json:"creds"`
Description string `json:"description"`
History int `json:"history"`
MaxBytes int `json:"maxBytes"`
MaxValueSize int `json:"maxValueSize"`
Mirror *StreamSource `json:"mirror"`
Name string `json:"name"`
Nkey string `json:"nkey"`
Placement *StreamPlacement `json:"placement"`
PreventDelete bool `json:"preventDelete"`
PreventUpdate bool `json:"preventUpdate"`
Replicas int `json:"replicas"`
Republish *RePublish `json:"republish"`
Servers []string `json:"servers"`
Sources []*StreamSource `json:"sources"`
Storage string `json:"storage"`
TLS TLS `json:"tls"`
TTL string `json:"ttl"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// KeyValueList is a list of Stream resources
type KeyValueList struct {
k8smeta.TypeMeta `json:",inline"`
k8smeta.ListMeta `json:"metadata"`

Items []KeyValue `json:"items"`
}
Loading

0 comments on commit 857f6a7

Please sign in to comment.