-
Notifications
You must be signed in to change notification settings - Fork 32
OLS-2101: switch to LSC app backend using magic configmap #1073
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
raptorsun
wants to merge
1
commit into
openshift:main
Choose a base branch
from
raptorsun:ols-2101
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| package controller | ||
|
|
||
| import ( | ||
| "context" | ||
|
|
||
| appsv1 "k8s.io/api/apps/v1" | ||
| corev1 "k8s.io/api/core/v1" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
|
|
||
| olsv1alpha1 "github.com/openshift/lightspeed-operator/api/v1alpha1" | ||
| ) | ||
|
|
||
| // todo: implement LSC config map generation | ||
| // | ||
| //nolint:unused // Ignore unused lint error before implementation of reconciliation functions | ||
| func (r *OLSConfigReconciler) generateLSCConfigMap(ctx context.Context, cr *olsv1alpha1.OLSConfig) (*corev1.ConfigMap, error) { //lint:ignore U1000 Ignore unused lint error before implementation of reconciliation functions | ||
| configMap := &corev1.ConfigMap{ | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Name: AppServerConfigCmName, | ||
| Namespace: r.Options.Namespace, | ||
| }, | ||
| } | ||
| return configMap, nil | ||
| } | ||
|
|
||
| // todo: implement LSC deployment generation | ||
| // | ||
| //nolint:unused // Ignore unused lint error before implementation of reconciliation functions | ||
| func (r *OLSConfigReconciler) generateLSCDeployment(ctx context.Context, cr *olsv1alpha1.OLSConfig) (*appsv1.Deployment, error) { //lint:ignore U1000 Ignore unused lint error before implementation of reconciliation functions | ||
| deployment := &appsv1.Deployment{ | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Name: OLSAppServerDeploymentName, | ||
| Namespace: r.Options.Namespace, | ||
| }, | ||
| Spec: appsv1.DeploymentSpec{ | ||
| Replicas: cr.Spec.OLSConfig.DeploymentConfig.Replicas, | ||
| Selector: &metav1.LabelSelector{ | ||
| MatchLabels: generateAppServerSelectorLabels(), | ||
| }, | ||
| Template: corev1.PodTemplateSpec{ | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Labels: generateAppServerSelectorLabels(), | ||
| }, | ||
| Spec: corev1.PodSpec{ | ||
| Containers: []corev1.Container{ | ||
| { | ||
| Name: "lsc-app-server", | ||
| Image: r.Options.LightspeedServiceImage, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
| return deployment, nil | ||
| } | ||
|
|
||
| // todo: implement LSC deployment update | ||
| // | ||
| //nolint:unused // Ignore unused lint error before implementation of reconciliation functions | ||
| func (r *OLSConfigReconciler) updateLSCDeployment(ctx context.Context, existingDeployment, desiredDeployment *appsv1.Deployment) error { | ||
|
|
||
| return nil | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| package controller | ||
|
|
||
| import ( | ||
| "context" | ||
|
|
||
| . "github.com/onsi/ginkgo/v2" | ||
| . "github.com/onsi/gomega" | ||
| appsv1 "k8s.io/api/apps/v1" | ||
| logf "sigs.k8s.io/controller-runtime/pkg/log" | ||
|
|
||
| olsv1alpha1 "github.com/openshift/lightspeed-operator/api/v1alpha1" | ||
| ) | ||
|
|
||
| var _ = Describe("LSC App server assets", Label("LSCBackend"), Ordered, func() { | ||
| var cr *olsv1alpha1.OLSConfig | ||
| var r *OLSConfigReconciler | ||
| var rOptions *OLSConfigReconcilerOptions | ||
| var ctx context.Context | ||
|
|
||
| Context("LSC asset generation", func() { | ||
| BeforeEach(func() { | ||
| ctx = context.Background() | ||
| rOptions = &OLSConfigReconcilerOptions{ | ||
| OpenShiftMajor: "123", | ||
| OpenshiftMinor: "456", | ||
| LightspeedServiceImage: "lightspeed-service:latest", | ||
| OpenShiftMCPServerImage: "openshift-mcp-server:latest", | ||
| Namespace: OLSNamespaceDefault, | ||
| } | ||
| cr = getDefaultOLSConfigCR() | ||
| r = &OLSConfigReconciler{ | ||
| Options: *rOptions, | ||
| logger: logf.Log.WithName("olsconfig.reconciler"), | ||
| Client: k8sClient, | ||
| Scheme: k8sClient.Scheme(), | ||
| stateCache: make(map[string]string), | ||
| } | ||
| }) | ||
|
|
||
| Describe("generateLSCConfigMap", func() { | ||
| It("should generate a valid configmap", func() { | ||
| cm, err := r.generateLSCConfigMap(ctx, cr) | ||
| Expect(err).NotTo(HaveOccurred()) | ||
| Expect(cm).NotTo(BeNil()) | ||
| }) | ||
|
|
||
| // TODO: Add more tests cases for once implementation is complete | ||
| }) | ||
|
|
||
| Describe("generateLSCDeployment", func() { | ||
| It("should generate a valid deployment", func() { | ||
| deployment, err := r.generateLSCDeployment(ctx, cr) | ||
| Expect(err).NotTo(HaveOccurred()) | ||
| Expect(deployment).NotTo(BeNil()) | ||
| }) | ||
|
|
||
| // TODO: Add more tests cases for once implementation is complete | ||
| }) | ||
|
|
||
| Describe("updateLSCDeployment", func() { | ||
| var existingDeployment *appsv1.Deployment | ||
| var desiredDeployment *appsv1.Deployment | ||
|
|
||
| BeforeEach(func() { | ||
| existingDeployment, _ = r.generateLSCDeployment(ctx, cr) | ||
| }) | ||
|
|
||
| It("should successfully update deployment", func() { | ||
| desiredDeployment, _ = r.generateLSCDeployment(ctx, cr) | ||
| err := r.updateLSCDeployment(ctx, existingDeployment, desiredDeployment) | ||
| Expect(err).NotTo(HaveOccurred()) | ||
| }) | ||
|
|
||
| // TODO: Add more tests cases for once implementation is complete | ||
| }) | ||
| }) | ||
|
|
||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| package controller | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
|
|
||
| olsv1alpha1 "github.com/openshift/lightspeed-operator/api/v1alpha1" | ||
| ) | ||
|
|
||
| func (r *OLSConfigReconciler) reconcileAppServerLSC(ctx context.Context, olsconfig *olsv1alpha1.OLSConfig) error { | ||
| r.logger.Info("reconcileAppServerLSC starts") | ||
| tasks := []ReconcileTask{ | ||
| { | ||
| Name: "reconcile ServiceAccount", | ||
| Task: r.reconcileServiceAccount, | ||
| }, | ||
| { | ||
| Name: "reconcile SARRole", | ||
| Task: r.reconcileSARRole, | ||
| }, | ||
| { | ||
| Name: "reconcile SARRoleBinding", | ||
| Task: r.reconcileSARRoleBinding, | ||
| }, | ||
| // todo: LSC config map generation | ||
| // todo: Llama Stack configmap generation | ||
| { | ||
| Name: "reconcile OLSConfigMap", | ||
| Task: r.reconcileLSCConfigMap, | ||
| }, | ||
| { | ||
| Name: "reconcile Additional CA ConfigMap", | ||
| Task: r.reconcileOLSAdditionalCAConfigMap, | ||
| }, | ||
| { | ||
| Name: "reconcile App Service", | ||
| Task: r.reconcileService, | ||
| }, | ||
| { | ||
| Name: "reconcile App TLS Certs", | ||
| Task: r.reconcileTLSSecret, | ||
| }, | ||
| // todo: LSC deployment generation | ||
| { | ||
| Name: "reconcile App Deployment", | ||
| Task: r.reconcileLSCDeployment, | ||
| }, | ||
| { | ||
| Name: "reconcile Metrics Reader Secret", | ||
| Task: r.reconcileMetricsReaderSecret, | ||
| }, | ||
| { | ||
| Name: "reconcile App ServiceMonitor", | ||
| Task: r.reconcileServiceMonitor, | ||
| }, | ||
| { | ||
| Name: "reconcile App PrometheusRule", | ||
| Task: r.reconcilePrometheusRule, | ||
| }, | ||
| { | ||
| Name: "reconcile App NetworkPolicy", | ||
| Task: r.reconcileAppServerNetworkPolicy, | ||
| }, | ||
| { | ||
| Name: "reconcile Proxy CA ConfigMap", | ||
| Task: r.reconcileProxyCAConfigMap, | ||
| }, | ||
| } | ||
|
|
||
| for _, task := range tasks { | ||
| err := task.Task(ctx, olsconfig) | ||
| if err != nil { | ||
| r.logger.Error(err, "reconcileAppServer error", "task", task.Name) | ||
| return fmt.Errorf("failed to %s: %w", task.Name, err) | ||
| } | ||
| } | ||
|
|
||
| r.logger.Info("reconcileAppServer completes") | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| func (r *OLSConfigReconciler) reconcileLSCConfigMap(ctx context.Context, cr *olsv1alpha1.OLSConfig) error { | ||
|
|
||
| return r.reconcileOLSConfigMap(ctx, cr) | ||
| // TODO: implement LSC configmap reconciliation | ||
| } | ||
|
|
||
| func (r *OLSConfigReconciler) reconcileLSCDeployment(ctx context.Context, cr *olsv1alpha1.OLSConfig) error { | ||
|
|
||
| return r.reconcileDeployment(ctx, cr) | ||
|
|
||
| // TODO: implement LSC deployment reconciliation | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be in deployment file rather than here to make it symmetric to the current one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's put the LSC backend related code in a dedicated file and when we remove the old code in future, we just need to remove the old deployment file and the switch code in the main controller loop.