Skip to content

Commit

Permalink
Merge pull request #54 from shopware/setup-scripts
Browse files Browse the repository at this point in the history
setup scripts
  • Loading branch information
TrayserCassa authored Oct 11, 2024
2 parents a7c0e61 + 95f3a23 commit e23d1b0
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 35 deletions.
16 changes: 4 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,8 @@ manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and Cust
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."

.PHONY: fmt
fmt: ## Run go fmt against code.
go fmt ./...

.PHONY: vet
vet: ## Run go vet against code.
go vet ./...

.PHONY: test
test: manifests generate fmt vet envtest ## Run tests.
test: manifests generate envtest ## Run tests.
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test ./... -coverprofile cover.out

GOLANGCI_LINT = $(shell pwd)/bin/golangci-lint
Expand All @@ -111,11 +103,11 @@ lint-fix: golangci-lint ## Run golangci-lint linter and perform fixes
##@ Build

.PHONY: build
build: manifests generate fmt vet ## Build manager binary.
build: manifests generate ## Build manager binary.
go build -o bin/manager cmd/manager.go

.PHONY: run
run: manifests generate fmt vet zap-pretty ## Run a controller from your host.
run: manifests generate zap-pretty ## Run a controller from your host.
go run ./cmd/manager.go --namespace ${NAMESPACE} --disable-checks --debug 2>&1 | $(ZAP_PRETTY) --all

# If you wish to build the manager image targeting other platforms you can use the --platform flag.
Expand Down Expand Up @@ -154,7 +146,7 @@ endif

.PHONY: install
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
$(KUSTOMIZE) build config/crd | $(KUBECTL) apply -f -
$(KUSTOMIZE) build config/crd | $(KUBECTL) apply --namespace ${NAMESPACE} -f -

.PHONY: uninstall
uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
Expand Down
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 e23d1b0

Please sign in to comment.