-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1312 from zimnx/mz/replace-node-uuid
Replace ScyllaCluster nodes using Host ID
- Loading branch information
Showing
374 changed files
with
51,564 additions
and
189 deletions.
There are no files selected for viewing
This file contains 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 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 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 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
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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 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,73 @@ | ||
// Copyright (c) 2023 ScyllaDB. | ||
|
||
package scyllaclient | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"net" | ||
"net/http" | ||
"time" | ||
|
||
api "github.com/go-openapi/runtime/client" | ||
"github.com/go-openapi/strfmt" | ||
"github.com/scylladb/scylla-operator/pkg/auth" | ||
scyllaclient "github.com/scylladb/scylladb-swagger-go-client/scylladb/gen/v2/client" | ||
"github.com/scylladb/scylladb-swagger-go-client/scylladb/gen/v2/client/config" | ||
) | ||
|
||
const ( | ||
agentPort = "10001" | ||
defaultTimeout = 30 * time.Second | ||
) | ||
|
||
type ConfigClient struct { | ||
client *scyllaclient.ScylladbV2 | ||
} | ||
|
||
func NewConfigClient(host, authToken string) *ConfigClient { | ||
var transport http.RoundTripper = DefaultTransport() | ||
transport = fixContentType(transport) | ||
transport = auth.AddToken(transport, authToken) | ||
|
||
client := &http.Client{ | ||
Timeout: defaultTimeout, | ||
Transport: transport, | ||
} | ||
|
||
host = net.JoinHostPort(host, agentPort) | ||
|
||
scyllaV2Runtime := api.NewWithClient( | ||
host, scyllaclient.DefaultBasePath, scyllaclient.DefaultSchemes, client, | ||
) | ||
|
||
return &ConfigClient{ | ||
client: scyllaclient.New(scyllaV2Runtime, strfmt.Default), | ||
} | ||
} | ||
|
||
func (c *ConfigClient) BroadcastAddress(ctx context.Context) (string, error) { | ||
resp, err := c.client.Config.FindConfigBroadcastAddress(config.NewFindConfigBroadcastAddressParamsWithContext(ctx)) | ||
if err != nil { | ||
return "", fmt.Errorf("can't get broadcast_address: %w", err) | ||
} | ||
return resp.Payload, nil | ||
} | ||
|
||
// ReplaceAddressFirstBoot returns value of "replace_address_first_boot" config parameter. | ||
func (c *ConfigClient) ReplaceAddressFirstBoot(ctx context.Context) (string, error) { | ||
resp, err := c.client.Config.FindConfigReplaceAddressFirstBoot(config.NewFindConfigReplaceAddressFirstBootParamsWithContext(ctx)) | ||
if err != nil { | ||
return "", fmt.Errorf("can't get replace_address_first_boot: %w", err) | ||
} | ||
return resp.Payload, nil | ||
} | ||
|
||
// ReplaceNodeFirstBoot returns value of "replace_node_first_boot" config parameter. | ||
func (c *ConfigClient) ReplaceNodeFirstBoot(ctx context.Context) (string, error) { | ||
resp, err := c.client.Config.FindConfigReplaceNodeFirstBoot(config.NewFindConfigReplaceNodeFirstBootParamsWithContext(ctx)) | ||
if err != nil { | ||
return "", fmt.Errorf("can't get replace_node_first_boot: %w", err) | ||
} | ||
return resp.Payload, nil | ||
} |
This file contains 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,62 @@ | ||
// Copyright (c) 2023 ScyllaDB. | ||
|
||
package scyllafeatures | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/blang/semver" | ||
scyllav1 "github.com/scylladb/scylla-operator/pkg/api/scylla/v1" | ||
) | ||
|
||
var ( | ||
scyllaEnterpriseMinimalVersion = semver.MustParse("2000.0.0") | ||
) | ||
|
||
type ScyllaFeature string | ||
|
||
const ( | ||
ReplacingNodeUsingHostID ScyllaFeature = "ReplacingNodeUsingHostID" | ||
) | ||
|
||
type scyllaDBVersionMinimalConstraint struct { | ||
openSource semver.Version | ||
enterprise semver.Version | ||
} | ||
|
||
var featureMinimalVersionConstraints = map[ScyllaFeature]scyllaDBVersionMinimalConstraint{ | ||
ReplacingNodeUsingHostID: { | ||
openSource: semver.MustParse("5.2.0"), | ||
enterprise: semver.MustParse("2023.1.0"), | ||
}, | ||
} | ||
|
||
func Supports(sc *scyllav1.ScyllaCluster, feature ScyllaFeature) (bool, error) { | ||
constraints, ok := featureMinimalVersionConstraints[feature] | ||
if !ok { | ||
return false, fmt.Errorf("unable to find minimal version constraints, unknown feature %q", feature) | ||
} | ||
|
||
version, err := semver.Parse(sc.Spec.Version) | ||
if err != nil { | ||
return false, fmt.Errorf("can't parse ScyllaCluster version %q: %w", sc.Spec.Version, err) | ||
} | ||
|
||
if isOpenSource(version) && version.GTE(constraints.openSource) { | ||
return true, nil | ||
} | ||
|
||
if isEnterprise(version) && version.GTE(constraints.enterprise) { | ||
return true, nil | ||
} | ||
|
||
return false, nil | ||
} | ||
|
||
func isEnterprise(v semver.Version) bool { | ||
return v.GTE(scyllaEnterpriseMinimalVersion) | ||
} | ||
|
||
func isOpenSource(v semver.Version) bool { | ||
return v.LT(scyllaEnterpriseMinimalVersion) | ||
} |
This file contains 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 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 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
Oops, something went wrong.