Skip to content

Commit

Permalink
init ServiceRegistry (#223)
Browse files Browse the repository at this point in the history
Signed-off-by: spacewander <[email protected]>
  • Loading branch information
spacewander authored Jan 18, 2024
1 parent 25984a2 commit 2f7e536
Show file tree
Hide file tree
Showing 19 changed files with 1,065 additions and 0 deletions.
8 changes: 8 additions & 0 deletions controller/PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,12 @@ resources:
defaulting: true
validation: true
webhookVersion: v1
- api:
crdVersion: v1
namespaced: true
controller: true
group: mosn.io
kind: ServiceRegistry
path: mosn.io/htnn/controller/api/v1
version: v1
version: "3"
68 changes: 68 additions & 0 deletions controller/api/v1/serviceregistry_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
Copyright The HTNN Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1

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

// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.

// ServiceRegistrySpec defines the desired state of ServiceRegistry
type ServiceRegistrySpec struct {
// Type is the type of the service registry.
Type string `json:"type,omitempty"`
// Config is the configuration of the corresponding service registry.
Config runtime.RawExtension `json:"config,omitempty"`
}

// ServiceRegistryStatus defines the observed state of ServiceRegistry
type ServiceRegistryStatus struct {
// Conditions describe the current conditions.
//
// +optional
// +listType=map
// +listMapKey=type
Conditions []metav1.Condition `json:"conditions,omitempty"`
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status

// ServiceRegistry is the Schema for the serviceregistries API
type ServiceRegistry struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec ServiceRegistrySpec `json:"spec,omitempty"`
Status ServiceRegistryStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true

// ServiceRegistryList contains a list of ServiceRegistry
type ServiceRegistryList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []ServiceRegistry `json:"items"`
}

func init() {
SchemeBuilder.Register(&ServiceRegistry{}, &ServiceRegistryList{})
}
97 changes: 97 additions & 0 deletions controller/api/v1/zz_generated.deepcopy.go

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

13 changes: 13 additions & 0 deletions controller/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
mosniov1 "mosn.io/htnn/controller/api/v1"
"mosn.io/htnn/controller/internal/config"
"mosn.io/htnn/controller/internal/controller"
"mosn.io/htnn/controller/internal/registry"
"mosn.io/htnn/pkg/log"
)

Expand Down Expand Up @@ -111,6 +112,18 @@ func main() {
setupLog.Error(err, "unable to create controller", "controller", "Consumer")
os.Exit(1)
}

registry.InitRegistryManager(&registry.RegistryManagerOption{
Client: mgr.GetClient(),
})
if err = (&controller.ServiceRegistryReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "ServiceRegistry")
os.Exit(1)
}

if os.Getenv("ENABLE_WEBHOOKS") != "false" {
if err = (&mosniov1.HTTPFilterPolicy{}).SetupWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "HTTPFilterPolicy")
Expand Down
124 changes: 124 additions & 0 deletions controller/config/crd/bases/mosn.io_serviceregistries.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.13.0
name: serviceregistries.mosn.io
spec:
group: mosn.io
names:
kind: ServiceRegistry
listKind: ServiceRegistryList
plural: serviceregistries
singular: serviceregistry
scope: Namespaced
versions:
- name: v1
schema:
openAPIV3Schema:
description: ServiceRegistry is the Schema for the serviceregistries 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: ServiceRegistrySpec defines the desired state of ServiceRegistry
properties:
config:
type: object
x-kubernetes-preserve-unknown-fields: true
type:
description: Type is the type of the service registry.
type: string
type: object
status:
description: ServiceRegistryStatus defines the observed state of ServiceRegistry
properties:
conditions:
description: Conditions describe the current conditions.
items:
description: "Condition contains details for one aspect of the current
state of this API Resource. --- This struct is intended for direct
use as an array at the field path .status.conditions. For example,
\n type FooStatus struct{ // Represents the observations of a
foo's current state. // Known .status.conditions.type are: \"Available\",
\"Progressing\", and \"Degraded\" // +patchMergeKey=type // +patchStrategy=merge
// +listType=map // +listMapKey=type Conditions []metav1.Condition
`json:\"conditions,omitempty\" patchStrategy:\"merge\" patchMergeKey:\"type\"
protobuf:\"bytes,1,rep,name=conditions\"` \n // other fields }"
properties:
lastTransitionTime:
description: lastTransitionTime is the last time the condition
transitioned from one status to another. This should be when
the underlying condition changed. If that is not known, then
using the time when the API field changed is acceptable.
format: date-time
type: string
message:
description: message is a human readable message indicating
details about the transition. This may be an empty string.
maxLength: 32768
type: string
observedGeneration:
description: observedGeneration represents the .metadata.generation
that the condition was set based upon. For instance, if .metadata.generation
is currently 12, but the .status.conditions[x].observedGeneration
is 9, the condition is out of date with respect to the current
state of the instance.
format: int64
minimum: 0
type: integer
reason:
description: reason contains a programmatic identifier indicating
the reason for the condition's last transition. Producers
of specific condition types may define expected values and
meanings for this field, and whether the values are considered
a guaranteed API. The value should be a CamelCase string.
This field may not be empty.
maxLength: 1024
minLength: 1
pattern: ^[A-Za-z]([A-Za-z0-9_,:]*[A-Za-z0-9_])?$
type: string
status:
description: status of the condition, one of True, False, Unknown.
enum:
- "True"
- "False"
- Unknown
type: string
type:
description: type of condition in CamelCase or in foo.example.com/CamelCase.
--- Many .condition.type values are consistent across resources
like Available, but because arbitrary conditions can be useful
(see .node.status.conditions), the ability to deconflict is
important. The regex it matches is (dns1123SubdomainFmt/)?(qualifiedNameFmt)
maxLength: 316
pattern: ^([a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*/)?(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])$
type: string
required:
- lastTransitionTime
- message
- reason
- status
- type
type: object
type: array
x-kubernetes-list-map-keys:
- type
x-kubernetes-list-type: map
type: object
type: object
served: true
storage: true
subresources:
status: {}
3 changes: 3 additions & 0 deletions controller/config/crd/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,22 @@
resources:
- bases/mosn.io_httpfilterpolicies.yaml
- bases/mosn.io_consumers.yaml
- bases/mosn.io_serviceregistries.yaml
#+kubebuilder:scaffold:crdkustomizeresource

patches:
# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix.
# patches here are for enabling the conversion webhook for each CRD
- path: patches/webhook_in_httpfilterpolicies.yaml
- path: patches/webhook_in_consumers.yaml
#- path: patches/webhook_in_serviceregistries.yaml
#+kubebuilder:scaffold:crdkustomizewebhookpatch

# [CERTMANAGER] To enable cert-manager, uncomment all the sections with [CERTMANAGER] prefix.
# patches here are for enabling the CA injection for each CRD
- path: patches/cainjection_in_httpfilterpolicies.yaml
- path: patches/cainjection_in_consumers.yaml
#- path: patches/cainjection_in_serviceregistries.yaml
#+kubebuilder:scaffold:crdkustomizecainjectionpatch

# [WEBHOOK] To enable webhook, uncomment the following section
Expand Down
Loading

0 comments on commit 2f7e536

Please sign in to comment.