Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and Cust
output:rbac:artifacts:config=deploy/helm/jumpstarter/charts/jumpstarter-controller/templates/rbac/

cp deploy/helm/jumpstarter/crds/* deploy/operator/config/crd/bases/
cp deploy/helm/jumpstarter/crds/* deploy/helm/jumpstarter/charts/jumpstarter-controller/templates/crds/

.PHONY: generate
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
Expand Down
33 changes: 29 additions & 4 deletions api/v1alpha1/exporter_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"strings"

cpb "github.com/jumpstarter-dev/jumpstarter-controller/internal/protocol/jumpstarter/client/v1"
pb "github.com/jumpstarter-dev/jumpstarter-controller/internal/protocol/jumpstarter/v1"
"github.com/jumpstarter-dev/jumpstarter-controller/internal/service/utils"
"k8s.io/apimachinery/pkg/api/meta"
kclient "sigs.k8s.io/controller-runtime/pkg/client"
Expand All @@ -25,13 +26,37 @@ func (e *Exporter) Usernames(prefix string) []string {
}

func (e *Exporter) ToProtobuf() *cpb.Exporter {
// get online status from conditions
// get online status from conditions (deprecated, kept for backward compatibility)
isOnline := meta.IsStatusConditionTrue(e.Status.Conditions, string(ExporterConditionTypeOnline))

return &cpb.Exporter{
Name: utils.UnparseExporterIdentifier(kclient.ObjectKeyFromObject(e)),
Labels: e.Labels,
Online: isOnline,
Name: utils.UnparseExporterIdentifier(kclient.ObjectKeyFromObject(e)),
Labels: e.Labels,
Online: isOnline,
Status: stringToProtoStatus(e.Status.ExporterStatusValue),
StatusMessage: e.Status.StatusMessage,
}
}

// stringToProtoStatus converts the CRD string value to the proto ExporterStatus enum
func stringToProtoStatus(state string) pb.ExporterStatus {
switch state {
case ExporterStatusOffline:
return pb.ExporterStatus_EXPORTER_STATUS_OFFLINE
case ExporterStatusAvailable:
return pb.ExporterStatus_EXPORTER_STATUS_AVAILABLE
case ExporterStatusBeforeLeaseHook:
return pb.ExporterStatus_EXPORTER_STATUS_BEFORE_LEASE_HOOK
case ExporterStatusLeaseReady:
return pb.ExporterStatus_EXPORTER_STATUS_LEASE_READY
case ExporterStatusAfterLeaseHook:
return pb.ExporterStatus_EXPORTER_STATUS_AFTER_LEASE_HOOK
case ExporterStatusBeforeLeaseHookFailed:
return pb.ExporterStatus_EXPORTER_STATUS_BEFORE_LEASE_HOOK_FAILED
case ExporterStatusAfterLeaseHookFailed:
return pb.ExporterStatus_EXPORTER_STATUS_AFTER_LEASE_HOOK_FAILED
default:
return pb.ExporterStatus_EXPORTER_STATUS_UNSPECIFIED
}
}

Expand Down
19 changes: 19 additions & 0 deletions api/v1alpha1/exporter_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ type ExporterStatus struct {
LeaseRef *corev1.LocalObjectReference `json:"leaseRef,omitempty"`
LastSeen metav1.Time `json:"lastSeen,omitempty"`
Endpoint string `json:"endpoint,omitempty"`
// ExporterStatusValue is the current operational status reported by the exporter
// +kubebuilder:validation:Enum=Unspecified;Offline;Available;BeforeLeaseHook;LeaseReady;AfterLeaseHook;BeforeLeaseHookFailed;AfterLeaseHookFailed
ExporterStatusValue string `json:"exporterStatus,omitempty"`
// StatusMessage is an optional human-readable message describing the current state
StatusMessage string `json:"statusMessage,omitempty"`
}

type ExporterConditionType string
Expand All @@ -47,8 +52,22 @@ const (
ExporterConditionTypeOnline ExporterConditionType = "Online"
)

// ExporterStatus values - PascalCase for Kubernetes, converted from proto ALL_CAPS
const (
ExporterStatusUnspecified = "Unspecified"
ExporterStatusOffline = "Offline"
ExporterStatusAvailable = "Available"
ExporterStatusBeforeLeaseHook = "BeforeLeaseHook"
ExporterStatusLeaseReady = "LeaseReady"
ExporterStatusAfterLeaseHook = "AfterLeaseHook"
ExporterStatusBeforeLeaseHookFailed = "BeforeLeaseHookFailed"
ExporterStatusAfterLeaseHookFailed = "AfterLeaseHookFailed"
)

// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:printcolumn:name="Status",type="string",JSONPath=".status.exporterStatus"
// +kubebuilder:printcolumn:name="Message",type="string",JSONPath=".status.statusMessage",priority=1

// Exporter is the Schema for the exporters API
type Exporter struct {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
---
Copy link
Member

Choose a reason for hiding this comment

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

Not sure why they got added here, now they must be on the crd directory only

Image

apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.16.3
name: clients.jumpstarter.dev
spec:
group: jumpstarter.dev
names:
kind: Client
listKind: ClientList
plural: clients
singular: client
scope: Namespaced
versions:
- name: v1alpha1
schema:
openAPIV3Schema:
description: Client is the Schema for the identities API
properties:
apiVersion:
description: |-
APIVersion defines the versioned schema of this representation of an object.
Servers should convert recognized schemas to the latest internal value, and
may reject unrecognized values.
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
type: string
kind:
description: |-
Kind is a string value representing the REST resource this object represents.
Servers may infer this from the endpoint the client submits requests to.
Cannot be updated.
In CamelCase.
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
type: string
metadata:
type: object
spec:
description: ClientSpec defines the desired state of Identity
properties:
username:
type: string
type: object
status:
description: ClientStatus defines the observed state of Identity
properties:
credential:
description: Status field for the clients
properties:
name:
default: ""
description: |-
Name of the referent.
This field is effectively required, but due to backwards compatibility is
allowed to be empty. Instances of this type with an empty value here are
almost certainly wrong.
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
type: string
type: object
x-kubernetes-map-type: atomic
endpoint:
type: string
type: object
type: object
served: true
storage: true
subresources:
status: {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.16.3
name: exporteraccesspolicies.jumpstarter.dev
spec:
group: jumpstarter.dev
names:
kind: ExporterAccessPolicy
listKind: ExporterAccessPolicyList
plural: exporteraccesspolicies
singular: exporteraccesspolicy
scope: Namespaced
versions:
- name: v1alpha1
schema:
openAPIV3Schema:
description: ExporterAccessPolicy is the Schema for the exporteraccesspolicies
API.
properties:
apiVersion:
description: |-
APIVersion defines the versioned schema of this representation of an object.
Servers should convert recognized schemas to the latest internal value, and
may reject unrecognized values.
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
type: string
kind:
description: |-
Kind is a string value representing the REST resource this object represents.
Servers may infer this from the endpoint the client submits requests to.
Cannot be updated.
In CamelCase.
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
type: string
metadata:
type: object
spec:
description: ExporterAccessPolicySpec defines the desired state of ExporterAccessPolicy.
properties:
exporterSelector:
description: |-
A label selector is a label query over a set of resources. The result of matchLabels and
matchExpressions are ANDed. An empty label selector matches all objects. A null
label selector matches no objects.
properties:
matchExpressions:
description: matchExpressions is a list of label selector requirements.
The requirements are ANDed.
items:
description: |-
A label selector requirement is a selector that contains values, a key, and an operator that
relates the key and values.
properties:
key:
description: key is the label key that the selector applies
to.
type: string
operator:
description: |-
operator represents a key's relationship to a set of values.
Valid operators are In, NotIn, Exists and DoesNotExist.
type: string
values:
description: |-
values is an array of string values. If the operator is In or NotIn,
the values array must be non-empty. If the operator is Exists or DoesNotExist,
the values array must be empty. This array is replaced during a strategic
merge patch.
items:
type: string
type: array
x-kubernetes-list-type: atomic
required:
- key
- operator
type: object
type: array
x-kubernetes-list-type: atomic
matchLabels:
additionalProperties:
type: string
description: |-
matchLabels is a map of {key,value} pairs. A single {key,value} in the matchLabels
map is equivalent to an element of matchExpressions, whose key field is "key", the
operator is "In", and the values array contains only "value". The requirements are ANDed.
type: object
type: object
x-kubernetes-map-type: atomic
policies:
items:
properties:
from:
items:
properties:
clientSelector:
description: |-
A label selector is a label query over a set of resources. The result of matchLabels and
matchExpressions are ANDed. An empty label selector matches all objects. A null
label selector matches no objects.
properties:
matchExpressions:
description: matchExpressions is a list of label selector
requirements. The requirements are ANDed.
items:
description: |-
A label selector requirement is a selector that contains values, a key, and an operator that
relates the key and values.
properties:
key:
description: key is the label key that the selector
applies to.
type: string
operator:
description: |-
operator represents a key's relationship to a set of values.
Valid operators are In, NotIn, Exists and DoesNotExist.
type: string
values:
description: |-
values is an array of string values. If the operator is In or NotIn,
the values array must be non-empty. If the operator is Exists or DoesNotExist,
the values array must be empty. This array is replaced during a strategic
merge patch.
items:
type: string
type: array
x-kubernetes-list-type: atomic
required:
- key
- operator
type: object
type: array
x-kubernetes-list-type: atomic
matchLabels:
additionalProperties:
type: string
description: |-
matchLabels is a map of {key,value} pairs. A single {key,value} in the matchLabels
map is equivalent to an element of matchExpressions, whose key field is "key", the
operator is "In", and the values array contains only "value". The requirements are ANDed.
type: object
type: object
x-kubernetes-map-type: atomic
type: object
type: array
maximumDuration:
type: string
priority:
type: integer
spotAccess:
type: boolean
type: object
type: array
type: object
status:
description: ExporterAccessPolicyStatus defines the observed state of
ExporterAccessPolicy.
type: object
type: object
served: true
storage: true
subresources:
status: {}
Loading
Loading