Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/go_modules/github.com/cosmos/cosm…
Browse files Browse the repository at this point in the history
…os-db-1.1.1
  • Loading branch information
vimystic authored Feb 14, 2025
2 parents c909cbd + 4194f19 commit 2f48092
Show file tree
Hide file tree
Showing 24 changed files with 546 additions and 510 deletions.
19 changes: 8 additions & 11 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,28 +26,25 @@ linters-settings:
desc: "Although Ginkgo is used in kubebuilder, use testify instead. Ginkgo is bloated providing little value."
- pkg: github.com/onsi/ginkgo
desc: "Although Ginkgo is used in kubebuilder, use testify instead. Ginkgo is bloated providing little value."
govet:
check-shadowing: true
govet: {}
misspell:
locale: US
ignore-words:
- "statuser"
nakedret:
# make an issue if func has more lines of code than this setting and it has naked returns; default is 30
max-func-lines: 0 # completely disallow naked returns
max-func-lines: 0 # Completely disallow naked returns
nolintlint:
allow-leading-space: true # don't require machine-readable nolint directives (i.e. with no leading space)
allow-unused: false # report any unused nolint directives
require-explanation: false # don't require an explanation for nolint directives
require-specific: false # don't require nolint directives to be specific about which linter is being skipped
allow-unused: false # Report any unused nolint directives
require-explanation: false # Don't require an explanation for nolint directives
require-specific: false # Don't require nolint directives to be specific

linters:
disable-all: true
enable:
- bodyclose
- depguard
- errcheck
- exportloopref
- copyloopvar # Replaces exportloopref (Go 1.22+)
- goimports
- goprintffuncname
- gosimple
Expand All @@ -58,7 +55,7 @@ linters:
- noctx
- nolintlint
- staticcheck
- stylecheck # replacement for golint
- stylecheck # Replacement for golint
- unconvert
- unused
- whitespace
- whitespace
5 changes: 5 additions & 0 deletions api/v1/cosmosfullnode_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,11 @@ type InstanceOverridesSpec struct {
// Sets an individual instance's external address.
// +optional
ExternalAddress *string `json:"externalAddress"`

// NodeSelector is a selector which must be true for the pod to fit on a node.
// Selector which must match a node's labels for the pod to be scheduled on that node.
// +optional
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
}

type DisableStrategy string
Expand Down
7 changes: 7 additions & 0 deletions api/v1/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 config/crd/bases/cosmos.strange.love_cosmosfullnodes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,13 @@ spec:
image:
description: Overrides an individual instance's Image.
type: string
nodeSelector:
additionalProperties:
type: string
description: |-
NodeSelector is a selector which must be true for the pod to fit on a node.
Selector which must match a node's labels for the pod to be scheduled on that node.
type: object
volumeClaimTemplate:
description: Overrides an individual instance's PVC.
properties:
Expand Down
11 changes: 0 additions & 11 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,6 @@ rules:
- create
- patch
- update
- apiGroups:
- ""
resources:
- secrets
verbs:
- create
- get
- list
- patch
- update
- watch
- apiGroups:
- batch
resources:
Expand Down
13 changes: 6 additions & 7 deletions controllers/cosmosfullnode_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type CosmosFullNodeReconciler struct {

cacheController *cosmos.CacheController
configMapControl fullnode.ConfigMapControl
nodeKeyControl fullnode.NodeKeyControl
nodeKeyCollector *fullnode.NodeKeyCollector
peerCollector *fullnode.PeerCollector
podControl fullnode.PodControl
pvcControl fullnode.PVCControl
Expand All @@ -69,7 +69,7 @@ func NewFullNode(

cacheController: cacheController,
configMapControl: fullnode.NewConfigMapControl(client),
nodeKeyControl: fullnode.NewNodeKeyControl(client),
nodeKeyCollector: fullnode.NewNodeKeyCollector(client),
peerCollector: fullnode.NewPeerCollector(client),
podControl: fullnode.NewPodControl(client, cacheController),
pvcControl: fullnode.NewPVCControl(client),
Expand All @@ -93,7 +93,6 @@ var (
// Generate RBAC roles to watch and update resources. IMPORTANT!!!! All resource names must be lowercase or cluster role will not work.
//+kubebuilder:rbac:groups="",resources=pods;persistentvolumeclaims;services;serviceaccounts;configmaps,verbs=get;list;watch;create;update;patch;delete
//+kubebuilder:rbac:groups="rbac.authorization.k8s.io",resources=roles;rolebindings,verbs=get;list;watch;create;update;patch;delete;bind;escalate
//+kubebuilder:rbac:groups="",resources=secrets,verbs=get;list;watch;create;update;patch
//+kubebuilder:rbac:groups="",resources=events,verbs=create;update;patch

// Reconcile is part of the main kubernetes reconciliation loop which aims to
Expand Down Expand Up @@ -136,21 +135,21 @@ func (r *CosmosFullNodeReconciler) Reconcile(ctx context.Context, req ctrl.Reque
errs.Append(err)
}

// Reconcile Secrets.
err = r.nodeKeyControl.Reconcile(ctx, reporter, crd)
// Node keys are required for peers but created in config maps. Since config maps require peers, we need to resolve node keys first and pass them to both.
nodeKeys, err := r.nodeKeyCollector.Collect(ctx, crd)
if err != nil {
errs.Append(err)
}

// Find peer information that's used downstream.
peers, perr := r.peerCollector.Collect(ctx, crd)
peers, perr := r.peerCollector.Collect(ctx, crd, nodeKeys)
if perr != nil {
peers = peers.Default()
errs.Append(perr)
}

// Reconcile ConfigMaps.
configCksums, err := r.configMapControl.Reconcile(ctx, reporter, crd, peers)
configCksums, err := r.configMapControl.Reconcile(ctx, reporter, crd, peers, nodeKeys)
if err != nil {
errs.Append(err)
}
Expand Down
1 change: 0 additions & 1 deletion internal/cosmos/status_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ func (coll StatusCollector) Collect(ctx context.Context, pods []corev1.Pod) Stat
statuses := make(StatusCollection, len(pods))

for i := range pods {
i := i
eg.Go(func() error {
pod := pods[i]
statuses[i].TS = now
Expand Down
16 changes: 14 additions & 2 deletions internal/fullnode/configmap_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,18 @@ import (
"github.com/strangelove-ventures/cosmos-operator/internal/diff"
"github.com/strangelove-ventures/cosmos-operator/internal/kube"
corev1 "k8s.io/api/core/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
)

const (
configOverlayFile = "config-overlay.toml"
appOverlayFile = "app-overlay.toml"
nodeKeyFile = "node_key.json"
)

// BuildConfigMaps creates a ConfigMap with configuration to be mounted as files into containers.
// Currently, the config.toml (for Comet) and app.toml (for the Cosmos SDK).
func BuildConfigMaps(crd *cosmosv1.CosmosFullNode, peers Peers) ([]diff.Resource[*corev1.ConfigMap], error) {
// Currently, the config.toml (for Comet), app.toml (for the Cosmos SDK) and node_key.json.
func BuildConfigMaps(crd *cosmosv1.CosmosFullNode, peers Peers, nodeKeys NodeKeys) ([]diff.Resource[*corev1.ConfigMap], error) {
var (
buf = bufPool.Get().(*bytes.Buffer)
cms = make([]diff.Resource[*corev1.ConfigMap], 0, crd.Spec.Replicas)
Expand Down Expand Up @@ -66,6 +68,16 @@ func BuildConfigMaps(crd *cosmosv1.CosmosFullNode, peers Peers) ([]diff.Resource
}
buf.Reset()

nodeKey, ok := nodeKeys[client.ObjectKey{Name: instanceName(crd, i), Namespace: crd.Namespace}]

if !ok {
return nil, kube.UnrecoverableError(fmt.Errorf("node key not found for %s", instanceName(crd, i)))
}

nodeKeyValue := string(nodeKey.MarshaledNodeKey)

data[nodeKeyFile] = nodeKeyValue

var cm corev1.ConfigMap
cm.Name = instanceName(crd, i)
cm.Namespace = crd.Namespace
Expand Down
Loading

0 comments on commit 2f48092

Please sign in to comment.