Skip to content

Commit

Permalink
Handle the broker in the operator
Browse files Browse the repository at this point in the history
Fixes: #203
Signed-off-by: Stephen Kitt <skitt@redhat.com>
  • Loading branch information
skitt committed Feb 17, 2021
1 parent 1cf8473 commit fb970db
Show file tree
Hide file tree
Showing 21 changed files with 843 additions and 10 deletions.
2 changes: 2 additions & 0 deletions .yamllint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ ignore: |
/deploy/submariner/crds/submariner.io_gateways.yaml
/deploy/submariner/crds/submariner.io_endpoints.yaml
/deploy/submariner/crds/submariner.io_clusters.yaml
/deploy/crds/submariner.io_brokers.yaml
/deploy/crds/submariner.io_submariners.yaml
/deploy/crds/submariner.io_servicediscoveries.yaml
/deploy/mcsapi/crds/multicluster.x_k8s.io_serviceexports.yaml
/deploy/mcsapi/crds/multicluster.x_k8s.io_serviceimports.yaml
/config/crd/bases/submariner.io_brokers.yaml
/config/crd/bases/submariner.io_submariners.yaml
/config/crd/bases/submariner.io_servicediscoveries.yaml
/config/manager/kustomization.yaml
Expand Down
46 changes: 46 additions & 0 deletions apis/submariner/v1alpha1/submariner_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,54 @@ type SubmarinerList struct {
Items []Submariner `json:"items"`
}

// BrokerSpec defines the desired state of Broker
// +k8s:openapi-gen=true
type BrokerSpec struct {
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
// Important: Run "make" to regenerate code after modifying this file

Components []string `json:"components,omitempty"`
DefaultCustomDomains []string `json:"defaultCustomDomains,omitempty"`
GlobalnetCidrRange string `json:"globalnetCidrRange,omitempty"`
DefaultGlobalnetClusterSize uint `json:"defaultGlobalnetClusterSize"`
GlobalnetEnabled bool `json:"globalnetEnabled"`
}

// BrokerStatus defines the observed state of Broker
// +k8s:openapi-gen=true
type BrokerStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "make" to regenerate code after modifying this file
}

// +kubebuilder:object:root=true

// Broker is the Schema for the brokers API
// +k8s:openapi-gen=true
// +kubebuilder:subresource:status
// +kubebuilder:resource:path=brokers,scope=Namespaced
// +genclient
// +operator-sdk:csv:customresourcedefinitions:displayName="Broker"
type Broker struct { //nolint:maligned // we want to keep the traditional order
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec BrokerSpec `json:"spec,omitempty"`
Status BrokerStatus `json:"status,omitempty"`
}

// +kubebuilder:object:root=true

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

func init() {
SchemeBuilder.Register(&Submariner{}, &SubmarinerList{})
SchemeBuilder.Register(&Broker{}, &BrokerList{})
}

func (submariner *Submariner) SetDefaults() bool {
Expand Down
99 changes: 99 additions & 0 deletions apis/submariner/v1alpha1/zz_generated.deepcopy.go

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

70 changes: 70 additions & 0 deletions config/crd/bases/submariner.io_brokers.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@

---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.3.0
creationTimestamp: null
name: brokers.submariner.io
spec:
group: submariner.io
names:
kind: Broker
listKind: BrokerList
plural: brokers
singular: broker
scope: Namespaced
versions:
- name: v1alpha1
schema:
openAPIV3Schema:
description: Broker is the Schema for the brokers 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: BrokerSpec defines the desired state of Broker
properties:
components:
items:
type: string
type: array
defaultCustomDomains:
items:
type: string
type: array
defaultGlobalnetClusterSize:
type: integer
globalnetCidrRange:
type: string
globalnetEnabled:
type: boolean
required:
- defaultGlobalnetClusterSize
- globalnetEnabled
type: object
status:
description: BrokerStatus defines the observed state of Broker
type: object
type: object
served: true
storage: true
subresources:
status: {}
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
3 changes: 3 additions & 0 deletions config/crd/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,22 @@
resources:
# - bases/submariner.io_servicediscoveries.yaml
- bases/submariner.io_submariners.yaml
# - bases/submariner.io_brokers.yaml
# +kubebuilder:scaffold:crdkustomizeresource

patchesStrategicMerge:
# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix.
# patches here are for enabling the conversion webhook for each CRD
#- patches/webhook_in_submariners.yaml
#- patches/webhook_in_servicediscoveries.yaml
#- patches/webhook_in_brokers.yaml
# +kubebuilder:scaffold:crdkustomizewebhookpatch

# [CERTMANAGER] To enable webhook, uncomment all the sections with [CERTMANAGER] prefix.
# patches here are for enabling the CA injection for each CRD
#- patches/cainjection_in_submariners.yaml
#- patches/cainjection_in_servicediscoveries.yaml
#- patches/cainjection_in_brokers.yaml
# +kubebuilder:scaffold:crdkustomizecainjectionpatch

# the following config is for teaching kustomize how to do kustomization for CRDs.
Expand Down
8 changes: 8 additions & 0 deletions config/crd/patches/cainjection_in_brokers.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# The following patch adds a directive for certmanager to inject CA into the CRD
# CRD conversion requires k8s 1.13 or later.
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
annotations:
cert-manager.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME)
name: brokers.submariner.io
17 changes: 17 additions & 0 deletions config/crd/patches/webhook_in_brokers.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# The following patch enables conversion webhook for CRD
# CRD conversion requires k8s 1.13 or later.
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
name: brokers.submariner.io
spec:
conversion:
strategy: Webhook
webhookClientConfig:
# this is "\n" used as a placeholder, otherwise it will be rejected by the apiserver for being blank,
# but we're going to set it later using the cert-manager (or potentially a patch if not using cert-manager)
caBundle: Cg==
service:
namespace: system
name: webhook-service
path: /convert
1 change: 1 addition & 0 deletions config/samples/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
resources:
- lighthouse_v2alpha1_serviceexport.yaml
- lighthouse_v2alpha1_serviceimport.yaml
- submariner_v1alpha1_broker.yaml
- submariner_v1alpha1_submariner.yaml
- submariner_v1alpha1_servicediscovery.yaml
# +kubebuilder:scaffold:manifestskustomizesamples
10 changes: 10 additions & 0 deletions config/samples/submariner_v1alpha1_broker.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: submariner.io/v1alpha1
kind: Broker
metadata:
name: broker-sample
spec:
# defaultCustomDomains:
# globalnetCidrRange:
defaultGlobalnetClusterSize: 8192
globalnetEnabled: false
serviceDiscovery: true
Loading

0 comments on commit fb970db

Please sign in to comment.