Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ test-e2e:
go test ./test/e2e/ -v -ginkgo.v

GOLANGCI_LINT = $(shell pwd)/bin/golangci-lint
GOLANGCI_LINT_VERSION ?= v2.1.6
GOLANGCI_LINT_VERSION ?= v2.4.0
golangci-lint:
@[ -f $(GOLANGCI_LINT) ] || { \
set -e ;\
Expand Down
2 changes: 2 additions & 0 deletions api/v1alpha1/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,6 @@ type DeploymentOverrides struct {
Strategy *v1.DeploymentStrategy `json:"strategy,omitempty"`
Env []corev1.EnvVar `json:"env,omitempty"`
EnvFrom []corev1.EnvFromSource `json:"envFrom,omitempty"`
Volumes []corev1.Volume `json:"volumes,omitempty"`
VolumeMounts []corev1.VolumeMount `json:"volumeMounts,omitempty"`
}
14 changes: 14 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.

1,971 changes: 1,971 additions & 0 deletions config/crd/bases/teranode.bsvblockchain.org_alertsystems.yaml

Large diffs are not rendered by default.

1,971 changes: 1,971 additions & 0 deletions config/crd/bases/teranode.bsvblockchain.org_assets.yaml

Large diffs are not rendered by default.

1,971 changes: 1,971 additions & 0 deletions config/crd/bases/teranode.bsvblockchain.org_blockassemblies.yaml

Large diffs are not rendered by default.

1,971 changes: 1,971 additions & 0 deletions config/crd/bases/teranode.bsvblockchain.org_blockchains.yaml

Large diffs are not rendered by default.

1,971 changes: 1,971 additions & 0 deletions config/crd/bases/teranode.bsvblockchain.org_blockpersisters.yaml

Large diffs are not rendered by default.

1,971 changes: 1,971 additions & 0 deletions config/crd/bases/teranode.bsvblockchain.org_blockvalidators.yaml

Large diffs are not rendered by default.

66,057 changes: 48,021 additions & 18,036 deletions config/crd/bases/teranode.bsvblockchain.org_clusters.yaml

Large diffs are not rendered by default.

1,971 changes: 1,971 additions & 0 deletions config/crd/bases/teranode.bsvblockchain.org_coinbases.yaml

Large diffs are not rendered by default.

1,971 changes: 1,971 additions & 0 deletions config/crd/bases/teranode.bsvblockchain.org_legacies.yaml

Large diffs are not rendered by default.

1,971 changes: 1,971 additions & 0 deletions config/crd/bases/teranode.bsvblockchain.org_peers.yaml

Large diffs are not rendered by default.

1,971 changes: 1,971 additions & 0 deletions config/crd/bases/teranode.bsvblockchain.org_propagations.yaml

Large diffs are not rendered by default.

1,971 changes: 1,971 additions & 0 deletions config/crd/bases/teranode.bsvblockchain.org_pruners.yaml

Large diffs are not rendered by default.

1,971 changes: 1,971 additions & 0 deletions config/crd/bases/teranode.bsvblockchain.org_rpcs.yaml

Large diffs are not rendered by default.

1,971 changes: 1,971 additions & 0 deletions config/crd/bases/teranode.bsvblockchain.org_subtreevalidators.yaml

Large diffs are not rendered by default.

1,971 changes: 1,971 additions & 0 deletions config/crd/bases/teranode.bsvblockchain.org_utxopersisters.yaml

Large diffs are not rendered by default.

1,971 changes: 1,971 additions & 0 deletions config/crd/bases/teranode.bsvblockchain.org_validators.yaml

Large diffs are not rendered by default.

72 changes: 72 additions & 0 deletions internal/controller/cluster_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@
{fmt.Sprintf("%s-asset", cluster.Name), &teranodev1alpha1.Asset{}},
{fmt.Sprintf("%s-blockchain", cluster.Name), &teranodev1alpha1.Blockchain{}},
{fmt.Sprintf("%s-blockpersister", cluster.Name), &teranodev1alpha1.BlockPersister{}},
{fmt.Sprintf("%s-blockvalidator", cluster.Name), &teranodev1alpha1.BlockValidator{}},

Check failure on line 371 in internal/controller/cluster_controller_test.go

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Define a constant instead of duplicating this literal "%s-blockvalidator" 4 times.

See more on https://sonarcloud.io/project/issues?id=bsv-blockchain_teranode-operator&issues=AZrfRyvP-h1a3WPhDtvH&open=AZrfRyvP-h1a3WPhDtvH&pullRequest=27
{fmt.Sprintf("%s-coinbase", cluster.Name), &teranodev1alpha1.Coinbase{}},
{fmt.Sprintf("%s-legacy", cluster.Name), &teranodev1alpha1.Legacy{}},
{fmt.Sprintf("%s-propagation", cluster.Name), &teranodev1alpha1.Propagation{}},
Expand Down Expand Up @@ -449,6 +449,78 @@
Expect(dep.Spec.Template.Spec.ImagePullSecrets).To(ContainElements(customSecrets))
})

It("should append custom volumes and mounts when specified on service", func() {
cluster := &teranodev1alpha1.Cluster{}
err := k8sClient.Get(ctx, typeNamespacedName, cluster)
Expect(err).NotTo(HaveOccurred())

// Enable all components
enableAllServices(cluster)

// Define custom volume
customVolumes := []v1.Volume{
{Name: "custom-volume-1"},
{Name: "custom-volume-2"},
}

volumeMounts := []v1.VolumeMount{
{Name: "custom-volume-1", MountPath: "/mnt/custom1"},
{Name: "custom-volume-2", MountPath: "/mnt/custom2"},
}

cluster.Spec.BlockValidator.Spec.DeploymentOverrides = &teranodev1alpha1.DeploymentOverrides{}
cluster.Spec.BlockValidator.Spec.DeploymentOverrides.Volumes = customVolumes
cluster.Spec.BlockValidator.Spec.DeploymentOverrides.VolumeMounts = volumeMounts

// Update the cluster
Expect(k8sClient.Update(ctx, cluster)).To(Succeed())

// Reconcile
controllerReconciler := &ClusterReconciler{
Client: k8sClient,
Scheme: k8sClient.Scheme(),
}

_, err = controllerReconciler.Reconcile(ctx, reconcile.Request{
NamespacedName: typeNamespacedName,
})
Expect(err).NotTo(HaveOccurred())

// Verify pull secrets were applied to a component (e.g., Asset)
bv := &teranodev1alpha1.BlockValidator{}
Expect(k8sClient.Get(ctx, types.NamespacedName{
Name: fmt.Sprintf("%s-blockvalidator", cluster.Name),
Namespace: "default",
}, bv)).To(Succeed())
Expect(bv.Spec.DeploymentOverrides.Volumes).NotTo(BeNil())
Expect(bv.Spec.DeploymentOverrides.Volumes).To(ContainElements(customVolumes))
Expect(bv.Spec.DeploymentOverrides.VolumeMounts).NotTo(BeNil())
Expect(bv.Spec.DeploymentOverrides.VolumeMounts).To(ContainElements(volumeMounts))

// Reconcile block validator
bvReconciler := &BlockValidatorReconciler{
Client: k8sClient,
Scheme: k8sClient.Scheme(),
}

_, err = bvReconciler.Reconcile(ctx, reconcile.Request{
NamespacedName: types.NamespacedName{
Name: fmt.Sprintf("%s-blockvalidator", cluster.Name),
Namespace: "default",
},
})
Expect(err).NotTo(HaveOccurred())

// fetch block validator deployment to verify volumes are set there too
dep := &appsv1.Deployment{}
Expect(k8sClient.Get(ctx, types.NamespacedName{
Name: "block-validator",
Namespace: "default",
}, dep)).To(Succeed())
Expect(dep.Spec.Template.Spec.Volumes).To(ContainElements(customVolumes))
Expect(dep.Spec.Template.Spec.Containers[0].VolumeMounts).To(ContainElements(volumeMounts))
})

It("should disable all services when cluster is disabled", func() {
cluster := &teranodev1alpha1.Cluster{}
err := k8sClient.Get(ctx, typeNamespacedName, cluster)
Expand Down
8 changes: 8 additions & 0 deletions internal/controller/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ var _ = BeforeSuite(func() {
testEnv = &envtest.Environment{
CRDDirectoryPaths: []string{filepath.Join("..", "..", "config", "crd", "bases")},
ErrorIfCRDPathMissing: true,
ControlPlane: envtest.ControlPlane{
Etcd: &envtest.Etcd{
Args: []string{
"--max-request-bytes=5242880", // 5MB
"--max-txn-ops=10000",
},
},
},

// The BinaryAssetsDirectory is only required if you want to run the tests directly
// without call the makefile target test. If not informed it will look for the
Expand Down
7 changes: 7 additions & 0 deletions internal/utils/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,13 @@ func SetDeploymentOverrides(client client.Client, dep *appsv1.Deployment, cr v1a
}
dep.Spec.Template.Spec.ImagePullSecrets = append(dep.Spec.Template.Spec.ImagePullSecrets, *cr.DeploymentOverrides().ImagePullSecrets...)
}

if len(cr.DeploymentOverrides().Volumes) > 0 {
dep.Spec.Template.Spec.Volumes = append(dep.Spec.Template.Spec.Volumes, cr.DeploymentOverrides().Volumes...)
}
if len(cr.DeploymentOverrides().VolumeMounts) > 0 {
dep.Spec.Template.Spec.Containers[0].VolumeMounts = append(dep.Spec.Template.Spec.Containers[0].VolumeMounts, cr.DeploymentOverrides().VolumeMounts...)
}
}

func SetClusterOverrides(client client.Client, dep *appsv1.Deployment, cr v1alpha1.TeranodeService) {
Expand Down