Skip to content

Commit

Permalink
feat: use setupscript instead of hooks
Browse files Browse the repository at this point in the history
This makes it possible to use specific commands and check the output for
the setup command. The default will be /setup.
  • Loading branch information
TrayserCassa committed Oct 11, 2024
1 parent a7c0e61 commit a9a463b
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 23 deletions.
6 changes: 6 additions & 0 deletions api/v1/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,15 @@ type StoreSpec struct {
// +kubebuilder:default={username: "admin", password: ""}
AdminCredentials Credentials `json:"adminCredentials"`

//+kubebuilder:deprecatedversion
SetupHook Hook `json:"setupHook,omitempty"`
// +kubebuilder:default=/setup
SetupScript string `json:"setupScript,omitempty"`

//+kubebuilder:deprecatedversion
MigrationHook Hook `json:"migrationHook,omitempty"`
// +kubebuilder:default=/setup
MigrationScript string `json:"migrationScript,omitempty"`
}

func init() {
Expand Down
3 changes: 2 additions & 1 deletion internal/controller/store_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ func (r *StoreReconciler) doReconcile(
WithValues("state", store.Status.State)
log.Info("Do reconcile on store")

log.Info("reconcile app secrets")
if err := r.ensureAppSecrets(ctx, store); err != nil {
return fmt.Errorf("app secrets: %w", err)
}
Expand Down Expand Up @@ -318,7 +319,7 @@ func (r *StoreReconciler) reconcileServices(ctx context.Context, store *v1.Store
store.Namespace,
obj.Labels["app"]))
if err := k8s.EnsureService(ctx, r.Client, store, obj, r.Scheme, true); err != nil {
return fmt.Errorf("reconcile unready deployment: %w", err)
return fmt.Errorf("reconcile unready services: %w", err)
}
}
}
Expand Down
13 changes: 2 additions & 11 deletions internal/job/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,22 +55,13 @@ func MigrationJob(store *v1.Store) *batchv1.Job {
}
maps.Copy(annotations, store.Spec.Container.Annotations)

var commandString string
if store.Spec.SetupHook.Before != "" {
commandString = store.Spec.SetupHook.Before
}
commandString = fmt.Sprintf("%s %s", commandString, "/setup;")
if store.Spec.SetupHook.After != "" {
commandString = fmt.Sprintf("%s %s", commandString, store.Spec.SetupHook.After)
}

containers := append(store.Spec.Container.ExtraContainers, corev1.Container{
Name: CONTAINER_NAME_MIGRATION_JOB,
VolumeMounts: store.Spec.Container.VolumeMounts,
ImagePullPolicy: store.Spec.Container.ImagePullPolicy,
Image: store.Spec.Container.Image,
Command: []string{"sh"},
Args: []string{"-c", commandString},
Command: []string{"sh", "-c"},
Args: []string{store.Spec.MigrationScript},
Env: store.GetEnv(),
})

Expand Down
13 changes: 2 additions & 11 deletions internal/job/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,6 @@ func SetupJob(store *v1.Store) *batchv1.Job {
}
maps.Copy(labels, util.GetDefaultLabels(store))

var commandString string
if store.Spec.SetupHook.Before != "" {
commandString = store.Spec.SetupHook.Before
}
commandString = fmt.Sprintf("%s %s", commandString, "/setup;")
if store.Spec.SetupHook.After != "" {
commandString = fmt.Sprintf("%s %s", commandString, store.Spec.SetupHook.After)
}

envs := append(store.GetEnv(),
corev1.EnvVar{
Name: "INSTALL_ADMIN_PASSWORD",
Expand All @@ -71,8 +62,8 @@ func SetupJob(store *v1.Store) *batchv1.Job {
VolumeMounts: store.Spec.Container.VolumeMounts,
ImagePullPolicy: store.Spec.Container.ImagePullPolicy,
Image: store.Spec.Container.Image,
Command: []string{"sh"},
Args: []string{"-c", commandString},
Command: []string{"sh", "-c"},
Args: []string{store.Spec.SetupScript},
Env: envs,
})

Expand Down

0 comments on commit a9a463b

Please sign in to comment.