Skip to content

Commit

Permalink
Add APIs for the HTTPBootConfig (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
hardikdr authored Apr 25, 2024
1 parent d8f3829 commit a4ad15a
Show file tree
Hide file tree
Showing 13 changed files with 372 additions and 2 deletions.
9 changes: 9 additions & 0 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,13 @@ resources:
kind: IPXEBootConfig
path: github.com/ironcore-dev/ipxe-operator/api/v1alpha1
version: v1alpha1
- api:
crdVersion: v1
namespaced: true
controller: true
domain: ironcore.dev
group: boot
kind: HTTPBootConfig
path: github.com/ironcore-dev/ipxe-operator/api/v1alpha1
version: v1alpha1
version: "3"
61 changes: 61 additions & 0 deletions api/v1alpha1/httpbootconfig_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and IronCore contributors
// SPDX-License-Identifier: Apache-2.0

package v1alpha1

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

// HTTPBootConfigSpec defines the desired state of HTTPBootConfig
type HTTPBootConfigSpec struct {
SystemUUID string `json:"systemUUID,omitempty"`
SystemIPs []string `json:"systemIP,omitempty"` // TODO: Add the custom serialization. For now validate at the controller.

KernelURL string `json:"kernelURL,omitempty"`
InitrdURL string `json:"initrdURL,omitempty"`
SquashfsURL string `json:"squashfsURL,omitempty"`

IgnitionSecretRef *corev1.LocalObjectReference `json:"ignitionSecretRef,omitempty"`

CmdLine string `json:"cmdLine,omitempty"`
}

// HTTPBootConfigStatus defines the observed state of HTTPBootConfig
type HTTPBootConfigStatus struct {
State HTTPConfigState `json:"state,omitempty"`
}

type HTTPConfigState string

const (
HTTPConfigStateReady HTTPConfigState = "Ready"
HTTPConfigStatePending HTTPConfigState = "Pending"
HTTPConfigStateError HTTPConfigState = "Error"
)

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

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

Spec HTTPBootConfigSpec `json:"spec,omitempty"`
Status HTTPBootConfigStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true

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

func init() {
SchemeBuilder.Register(&HTTPBootConfig{}, &HTTPBootConfigList{})
}
1 change: 0 additions & 1 deletion api/v1alpha1/ipxebootconfig_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ const DefaultIgnitionKey = "ignition"

// IPXEBootConfigStatus defines the observed state of IPXEBootConfig
type IPXEBootConfigStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "make" to regenerate code after modifying this file
State IPXEBootConfigState `json:"state,omitempty"`
}
Expand Down
91 changes: 90 additions & 1 deletion api/v1alpha1/zz_generated.deepcopy.go

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

7 changes: 7 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,13 @@ func main() {
os.Exit(1)
}
}
if err = (&controller.HTTPBootConfigReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "HTTPBootConfig")
os.Exit(1)
}
//+kubebuilder:scaffold:builder

if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil {
Expand Down
3 changes: 3 additions & 0 deletions config/crd/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,20 @@
# It should be run by config/default
resources:
- bases/boot.ironcore.dev_ipxebootconfigs.yaml
- bases/boot.ironcore.dev_httpbootconfigs.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_ipxebootconfigs.yaml
#- path: patches/webhook_in_httpbootconfigs.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_ipxebootconfigs.yaml
#- path: patches/cainjection_in_httpbootconfigs.yaml
#+kubebuilder:scaffold:crdkustomizecainjectionpatch

# [WEBHOOK] To enable webhook, uncomment the following section
Expand Down
31 changes: 31 additions & 0 deletions config/rbac/httpbootconfig_editor_role.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# permissions for end users to edit httpbootconfigs.
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
labels:
app.kubernetes.io/name: clusterrole
app.kubernetes.io/instance: httpbootconfig-editor-role
app.kubernetes.io/component: rbac
app.kubernetes.io/created-by: ipxe-operator
app.kubernetes.io/part-of: ipxe-operator
app.kubernetes.io/managed-by: kustomize
name: httpbootconfig-editor-role
rules:
- apiGroups:
- boot.ironcore.dev
resources:
- httpbootconfigs
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- boot.ironcore.dev
resources:
- httpbootconfigs/status
verbs:
- get
27 changes: 27 additions & 0 deletions config/rbac/httpbootconfig_viewer_role.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# permissions for end users to view httpbootconfigs.
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
labels:
app.kubernetes.io/name: clusterrole
app.kubernetes.io/instance: httpbootconfig-viewer-role
app.kubernetes.io/component: rbac
app.kubernetes.io/created-by: ipxe-operator
app.kubernetes.io/part-of: ipxe-operator
app.kubernetes.io/managed-by: kustomize
name: httpbootconfig-viewer-role
rules:
- apiGroups:
- boot.ironcore.dev
resources:
- httpbootconfigs
verbs:
- get
- list
- watch
- apiGroups:
- boot.ironcore.dev
resources:
- httpbootconfigs/status
verbs:
- get
20 changes: 20 additions & 0 deletions config/samples/httpbootconfig.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
apiVersion: boot.ironcore.dev/v1alpha1
kind: HTTPBootConfig
metadata:
labels:
app.kubernetes.io/name: httpbootconfig
app.kubernetes.io/instance: httpbootconfig-sample
app.kubernetes.io/part-of: ipxe-operator
app.kubernetes.io/managed-by: kustomize
app.kubernetes.io/created-by: ipxe-operator
name: httpbootconfig-sample
spec:
systemUUID: 1234
systemIPs:
- 1.2.3.4
ignitionSecretRef:
name: ignition-sample
kernelURL: "10.0.0.1/ipxe/rootfs.vmlinuz"
initrdURL: "10.0.0.1/ipxe/rootfs.initrd"
squashfsURL: "10.0.0.1/ipxe/root.squashfs"

1 change: 1 addition & 0 deletions config/samples/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
## Append samples of your project ##
resources:
- boot_v1alpha1_ipxebootconfig.yaml
- boot_v1alpha1_httpbootconfig.yaml
#+kubebuilder:scaffold:manifestskustomizesamples
49 changes: 49 additions & 0 deletions internal/controller/httpbootconfig_controller.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and IronCore contributors
// SPDX-License-Identifier: Apache-2.0

package controller

import (
"context"

"k8s.io/apimachinery/pkg/runtime"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/log"

bootv1alpha1 "github.com/ironcore-dev/ipxe-operator/api/v1alpha1"
)

// HTTPBootConfigReconciler reconciles a HTTPBootConfig object
type HTTPBootConfigReconciler struct {
client.Client
Scheme *runtime.Scheme
}

//+kubebuilder:rbac:groups=boot.ironcore.dev,resources=httpbootconfigs,verbs=get;list;watch;create;update;patch;delete
//+kubebuilder:rbac:groups=boot.ironcore.dev,resources=httpbootconfigs/status,verbs=get;update;patch
//+kubebuilder:rbac:groups=boot.ironcore.dev,resources=httpbootconfigs/finalizers,verbs=update

// Reconcile is part of the main kubernetes reconciliation loop which aims to
// move the current state of the cluster closer to the desired state.
// TODO(user): Modify the Reconcile function to compare the state specified by
// the HTTPBootConfig object against the actual cluster state, and then
// perform operations to make the cluster state reflect the state specified by
// the user.
//
// For more details, check Reconcile and its Result here:
// - https://pkg.go.dev/sigs.k8s.io/[email protected]/pkg/reconcile
func (r *HTTPBootConfigReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
_ = log.FromContext(ctx)

// TODO(user): your logic here

return ctrl.Result{}, nil
}

// SetupWithManager sets up the controller with the Manager.
func (r *HTTPBootConfigReconciler) SetupWithManager(mgr ctrl.Manager) error {
return ctrl.NewControllerManagedBy(mgr).
For(&bootv1alpha1.HTTPBootConfig{}).
Complete(r)
}
Loading

0 comments on commit a4ad15a

Please sign in to comment.