Skip to content

Commit

Permalink
Add microvm kind
Browse files Browse the repository at this point in the history
```
kubebuilder create api \
  --group infrastructure \
  --version v1alpha1 \
  --kind Microvm
```

My go installation was weird. It was using 1.19.x but trying to use
`tools` from `/usr/lib/go-1.18`. Fixed by changing `GOROOT`.
  • Loading branch information
Callisto13 committed Nov 15, 2022
1 parent 1ded05e commit 251edca
Show file tree
Hide file tree
Showing 16 changed files with 515 additions and 0 deletions.
10 changes: 10 additions & 0 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,14 @@ layout:
- go.kubebuilder.io/v3
projectName: microvm-operator
repo: github.com/weaveworks-liquidmetal/microvm-operator
resources:
- api:
crdVersion: v1
namespaced: true
controller: true
domain: flintlock.x-k8s.io
group: infrastructure
kind: Microvm
path: github.com/weaveworks-liquidmetal/microvm-operator/api/v1alpha1
version: v1alpha1
version: "3"
36 changes: 36 additions & 0 deletions api/v1alpha1/groupversion_info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
Copyright 2022 Weaveworks.
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 v1alpha1 contains API Schema definitions for the infrastructure v1alpha1 API group
// +kubebuilder:object:generate=true
// +groupName=infrastructure.flintlock.x-k8s.io
package v1alpha1

import (
"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/controller-runtime/pkg/scheme"
)

var (
// GroupVersion is group version used to register these objects
GroupVersion = schema.GroupVersion{Group: "infrastructure.flintlock.x-k8s.io", Version: "v1alpha1"}

// SchemeBuilder is used to add go types to the GroupVersionKind scheme
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}

// AddToScheme adds the types in this group-version to the given scheme.
AddToScheme = SchemeBuilder.AddToScheme
)
64 changes: 64 additions & 0 deletions api/v1alpha1/microvm_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
Copyright 2022 Weaveworks.
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 v1alpha1

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

// 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.

// MicrovmSpec defines the desired state of Microvm
type MicrovmSpec struct {
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
// Important: Run "make" to regenerate code after modifying this file

// Foo is an example field of Microvm. Edit microvm_types.go to remove/update
Foo string `json:"foo,omitempty"`
}

// MicrovmStatus defines the observed state of Microvm
type MicrovmStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "make" to regenerate code after modifying this file
}

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

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

Spec MicrovmSpec `json:"spec,omitempty"`
Status MicrovmStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true

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

func init() {
SchemeBuilder.Register(&Microvm{}, &MicrovmList{})
}
115 changes: 115 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

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

21 changes: 21 additions & 0 deletions config/crd/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# This kustomization.yaml is not intended to be run by itself,
# since it depends on service name and namespace that are out of this kustomize package.
# It should be run by config/default
resources:
- bases/infrastructure.flintlock.x-k8s.io_microvms.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_microvms.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
#- patches/cainjection_in_microvms.yaml
#+kubebuilder:scaffold:crdkustomizecainjectionpatch

# the following config is for teaching kustomize how to do kustomization for CRDs.
configurations:
- kustomizeconfig.yaml
19 changes: 19 additions & 0 deletions config/crd/kustomizeconfig.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# This file is for teaching kustomize how to substitute name and namespace reference in CRD
nameReference:
- kind: Service
version: v1
fieldSpecs:
- kind: CustomResourceDefinition
version: v1
group: apiextensions.k8s.io
path: spec/conversion/webhook/clientConfig/service/name

namespace:
- kind: CustomResourceDefinition
version: v1
group: apiextensions.k8s.io
path: spec/conversion/webhook/clientConfig/service/namespace
create: false

varReference:
- path: metadata/annotations
7 changes: 7 additions & 0 deletions config/crd/patches/cainjection_in_microvms.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# The following patch adds a directive for certmanager to inject CA into the CRD
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
cert-manager.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME)
name: microvms.infrastructure.flintlock.x-k8s.io
16 changes: 16 additions & 0 deletions config/crd/patches/webhook_in_microvms.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# The following patch enables a conversion webhook for the CRD
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: microvms.infrastructure.flintlock.x-k8s.io
spec:
conversion:
strategy: Webhook
webhook:
clientConfig:
service:
namespace: system
name: webhook-service
path: /convert
conversionReviewVersions:
- v1
31 changes: 31 additions & 0 deletions config/rbac/microvm_editor_role.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# permissions for end users to edit microvms.
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
labels:
app.kubernetes.io/name: clusterrole
app.kubernetes.io/instance: microvm-editor-role
app.kubernetes.io/component: rbac
app.kubernetes.io/created-by: microvm-operator
app.kubernetes.io/part-of: microvm-operator
app.kubernetes.io/managed-by: kustomize
name: microvm-editor-role
rules:
- apiGroups:
- infrastructure.flintlock.x-k8s.io
resources:
- microvms
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- infrastructure.flintlock.x-k8s.io
resources:
- microvms/status
verbs:
- get
27 changes: 27 additions & 0 deletions config/rbac/microvm_viewer_role.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# permissions for end users to view microvms.
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
labels:
app.kubernetes.io/name: clusterrole
app.kubernetes.io/instance: microvm-viewer-role
app.kubernetes.io/component: rbac
app.kubernetes.io/created-by: microvm-operator
app.kubernetes.io/part-of: microvm-operator
app.kubernetes.io/managed-by: kustomize
name: microvm-viewer-role
rules:
- apiGroups:
- infrastructure.flintlock.x-k8s.io
resources:
- microvms
verbs:
- get
- list
- watch
- apiGroups:
- infrastructure.flintlock.x-k8s.io
resources:
- microvms/status
verbs:
- get
12 changes: 12 additions & 0 deletions config/samples/infrastructure_v1alpha1_microvm.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: infrastructure.flintlock.x-k8s.io/v1alpha1
kind: Microvm
metadata:
labels:
app.kubernetes.io/name: microvm
app.kubernetes.io/instance: microvm-sample
app.kubernetes.io/part-of: microvm-operator
app.kuberentes.io/managed-by: kustomize
app.kubernetes.io/created-by: microvm-operator
name: microvm-sample
spec:
# TODO(user): Add fields here
Loading

0 comments on commit 251edca

Please sign in to comment.