Skip to content

Commit

Permalink
Merge pull request #3749 from telepresenceio/thallgren/drop-cluster-id
Browse files Browse the repository at this point in the history
Get rid of old code that retrieves "clusterID".
  • Loading branch information
thallgren authored Dec 17, 2024
2 parents ffc175f + d942dc1 commit b0dc2e3
Show file tree
Hide file tree
Showing 15 changed files with 490 additions and 557 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ docDescription: >-
environments, access to instantaneous feedback loops, and highly
customizable development environments.
items:
- version: 2.22.0
date: (TBD)
notes:
- type: change
title: Drop deprecated current-cluster-id command.
body: >-
The clusterID was deprecated some time ago, and replaced by the ID of the namespace where the traffic-manager
is installed.
- version: 2.21.1
date: 2024-12-17
notes:
Expand Down
29 changes: 7 additions & 22 deletions cmd/traffic/cmd/manager/cluster/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ type Info interface {
// ID of the installed ns
ID() string

// clusterID of the cluster
ClusterID() string

// SetAdditionalAlsoProxy assigns a slice that will be added to the Routing.AlsoProxySubnets slice
// when notifications are sent.
SetAdditionalAlsoProxy(ctx context.Context, subnets []*rpc.IPNet)
Expand All @@ -64,9 +61,6 @@ type info struct {

// installID is the UID of the manager's namespace
installID string

// clusterID is the UID of the default namespace
clusterID string
}

const IDZero = "00000000-0000-0000-0000-000000000000"
Expand Down Expand Up @@ -101,23 +95,12 @@ func NewInfo(ctx context.Context) Info {

client := ki.CoreV1()
if oi.installID, err = GetInstallIDFunc(ctx, client, env.ManagerNamespace); err != nil {
// We use a default clusterID because we don't want to fail if
// the traffic-manager doesn't have the ability to get the namespace
// Use a default installID because we don't want to fail if the traffic-manager can't get the namespace
oi.installID = IDZero
dlog.Warnf(ctx, "unable to get namespace \"%s\", will use default installID: %s: %v",
env.ManagerNamespace, oi.installID, err)
}

// backwards compat
// TODO delete after default ns licenses expire
if oi.clusterID, err = GetInstallIDFunc(ctx, client, "default"); err != nil {
// We use a default clusterID because we don't want to fail if
// the traffic-manager doesn't have the ability to get the namespace
oi.clusterID = IDZero
dlog.Infof(ctx,
"unable to get namespace \"default\", but it is only necessary for compatibility with old licesnses: %v", err)
}

dummyIP := "1.1.1.1"
if managerutil.AgentInjectorEnabled(ctx) {
oi.InjectorSvcIp, oi.InjectorSvcPort, err = getInjectorSvcIP(ctx, env, client)
Expand Down Expand Up @@ -377,6 +360,12 @@ func (oi *info) watchPodSubnets(ctx context.Context, namespaces []string) {
func (oi *info) setSubnetsFromEnv(ctx context.Context) bool {
subnets := managerutil.GetEnv(ctx).PodCIDRs
if len(subnets) > 0 {
mgrIp, _ := netip.AddrFromSlice(oi.ManagerPodIp)
if !slices.ContainsFunc(subnets, func(s netip.Prefix) bool { return s.Contains(mgrIp) }) {
sn := netip.PrefixFrom(mgrIp, mgrIp.BitLen())
dlog.Infof(ctx, "Adding %s for the traffic-manager pod, because it was not included in POD_CIDRS environment", sn)
subnets = append(subnets, sn)
}
oi.PodSubnets = iputil.PrefixesToRPC(subnets)
oi.ciSubs.notify(ctx, oi.clusterInfo())
dlog.Infof(ctx, "Using subnets from POD_CIDRS environment variable")
Expand Down Expand Up @@ -407,10 +396,6 @@ func (oi *info) ID() string {
return oi.installID
}

func (oi *info) ClusterID() string {
return oi.clusterID
}

func (oi *info) ClusterDomain() string {
return oi.Dns.ClusterDomain
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/traffic/cmd/manager/cluster/info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"github.com/telepresenceio/telepresence/v2/cmd/traffic/cmd/manager/managerutil"
)

func TestNewInfo_GetClusterID(t *testing.T) {
func TestNewInfo_GetInstallID(t *testing.T) {
env := managerutil.Env{
ManagedNamespaces: []string{"ambassador test"},
ManagerNamespace: "test",
Expand All @@ -41,7 +41,7 @@ func TestNewInfo_GetClusterID(t *testing.T) {
t.Run("from default namespace", func(t *testing.T) {
ctx := context.Background()

cs := fake.NewSimpleClientset(append(namespaces,
cs := fake.NewClientset(append(namespaces,
&v1.Namespace{
ObjectMeta: metav1.ObjectMeta{
Name: "default",
Expand All @@ -62,7 +62,7 @@ func TestNewInfo_GetClusterID(t *testing.T) {
t.Run("from non-default namespace", func(t *testing.T) {
ctx := context.Background()

cs := fake.NewSimpleClientset(namespaces...)
cs := fake.NewClientset(namespaces...)

ctx = k8sapi.WithK8sInterface(ctx, cs)
ctx = managerutil.WithEnv(ctx, &env)
Expand Down
15 changes: 5 additions & 10 deletions cmd/traffic/cmd/manager/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ type Service interface {
rpc.ManagerServer
ID() string
InstallID() string
ClusterID() string
MakeInterceptID(context.Context, string, string) (string, error)
RegisterServers(*grpc.Server)
State() state.State
Expand Down Expand Up @@ -133,10 +132,6 @@ func (s *service) InstallID() string {
return s.clusterInfo.ID()
}

func (s *service) ClusterID() string {
return s.clusterInfo.ClusterID()
}

func (s *service) runConfigWatcher(ctx context.Context) error {
return s.configWatcher.Run(ctx)
}
Expand Down Expand Up @@ -211,9 +206,9 @@ func (s *service) ArriveAsClient(ctx context.Context, client *rpc.ClientInfo) (*
SetGauge(s.state.GetConnectActiveStatus(), client.Name, client.InstallId, nil, 1)

return &rpc.SessionInfo{
SessionId: s.state.AddClient(client, s.clock.Now()),
ClusterId: s.clusterInfo.ID(),
InstallId: &installId,
SessionId: s.state.AddClient(client, s.clock.Now()),
ManagerInstallId: s.clusterInfo.ID(),
InstallId: &installId,
}, nil
}

Expand All @@ -232,8 +227,8 @@ func (s *service) ArriveAsAgent(ctx context.Context, agent *rpc.AgentInfo) (*rpc
sessionID := s.state.AddAgent(agent, s.clock.Now())

return &rpc.SessionInfo{
SessionId: sessionID,
ClusterId: s.clusterInfo.ID(),
SessionId: sessionID,
ManagerInstallId: s.clusterInfo.ID(),
}, nil
}

Expand Down
8 changes: 4 additions & 4 deletions cmd/traffic/cmd/manager/state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ func (s *state) WatchWorkloads(ctx context.Context, sessionID string) (ch <-chan

// Intercepts //////////////////////////////////////////////////////////////////////////////////////

func (s *state) AddIntercept(ctx context.Context, sessionID, clusterID string, cir *rpc.CreateInterceptRequest) (client *rpc.ClientInfo, ret *rpc.InterceptInfo, err error) {
func (s *state) AddIntercept(ctx context.Context, sessionID, managerID string, cir *rpc.CreateInterceptRequest) (client *rpc.ClientInfo, ret *rpc.InterceptInfo, err error) {
s.mu.Lock()
defer s.mu.Unlock()

Expand All @@ -523,9 +523,9 @@ func (s *state) AddIntercept(ctx context.Context, sessionID, clusterID string, c
interceptID := fmt.Sprintf("%s:%s", sessionID, spec.Name)
installID := client.GetInstallId()
clientSession := rpc.SessionInfo{
SessionId: sessionID,
ClusterId: clusterID,
InstallId: &installID,
SessionId: sessionID,
ManagerInstallId: managerID,
InstallId: &installID,
}

cept := s.self.NewInterceptInfo(interceptID, &clientSession, cir)
Expand Down
7 changes: 7 additions & 0 deletions docs/release-notes.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@

[comment]: # (Code generated by relnotesgen. DO NOT EDIT.)
# <img src="images/logo.png" height="64px"/> Telepresence Release Notes
## Version 2.22.0
## <div style="display:flex;"><img src="images/change.png" alt="change" style="width:30px;height:fit-content;"/><div style="display:flex;margin-left:7px;">Drop deprecated current-cluster-id command.</div></div>
<div style="margin-left: 15px">

The clusterID was deprecated some time ago, and replaced by the ID of the namespace where the traffic-manager is installed.
</div>

## Version 2.21.1 <span style="font-size: 16px;">(December 17)</span>
## <div style="display:flex;"><img src="images/bugfix.png" alt="bugfix" style="width:30px;height:fit-content;"/><div style="display:flex;margin-left:7px;">[Allow ingest of serverless deployments without specifying an inject-container-ports annotation](https://github.com/telepresenceio/telepresence/issues/3741)</div></div>
<div style="margin-left: 15px">
Expand Down
5 changes: 5 additions & 0 deletions docs/release-notes.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ import { Note, Title, Body } from '@site/src/components/ReleaseNotes'
[comment]: # (Code generated by relnotesgen. DO NOT EDIT.)

# Telepresence Release Notes
## Version 2.22.0
<Note>
<Title type="change">Drop deprecated current-cluster-id command.</Title>
<Body>The clusterID was deprecated some time ago, and replaced by the ID of the namespace where the traffic-manager is installed.</Body>
</Note>
## Version 2.21.1 <span style={{fontSize:'16px'}}>(December 17)</span>
<Note>
<Title type="bugfix" docs="https://github.com/telepresenceio/telepresence/issues/3741">Allow ingest of serverless deployments without specifying an inject-container-ports annotation</Title>
Expand Down
47 changes: 0 additions & 47 deletions pkg/client/cli/cmd/current_cluster_id.go

This file was deleted.

2 changes: 1 addition & 1 deletion pkg/client/cli/cmd/telepresence.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func OnlySubcommands(cmd *cobra.Command, args []string) error {

func WithSubCommands(ctx context.Context) context.Context {
return MergeSubCommands(ctx,
configCmd(), connectCmd(), currentClusterId(), gatherLogs(), genYAML(), helmCmd(),
configCmd(), connectCmd(), gatherLogs(), genYAML(), helmCmd(),
ingestCmd(), interceptCmd(), kubeauthCmd(), leave(), list(), listContexts(), listNamespaces(), loglevel(), quit(), statusCmd(),
dockerRunCmd(), curlCmd(),
uninstall(), version(), listNamespaces(), listContexts(),
Expand Down
5 changes: 0 additions & 5 deletions pkg/client/userd/k8s/k8s_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,11 +284,6 @@ func (kc *Cluster) GetCurrentNamespaces(forClientAccess bool) []string {
return nss
}

func (kc *Cluster) GetClusterId(ctx context.Context) string {
clusterID, _ := k8sapi.GetClusterID(ctx)
return clusterID
}

func (kc *Cluster) GetManagerInstallId(ctx context.Context) string {
managerID, _ := k8sapi.GetNamespaceID(ctx, GetManagerNamespace(ctx))
return managerID
Expand Down
3 changes: 0 additions & 3 deletions pkg/client/userd/trafficmgr/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,6 @@ func NewSession(
ctx = portforward.WithRestConfig(ctx, cluster.Kubeconfig.RestConfig)

ctx = cluster.WithJoinedClientSetInterface(ctx)
scout.SetMetadatum(ctx, "cluster_id", cluster.GetClusterId(ctx))

dlog.Info(ctx, "Connecting to traffic manager...")
installID, err := client.InstallID(ctx)
Expand Down Expand Up @@ -822,7 +821,6 @@ func (s *session) UpdateStatus(c context.Context, cri userd.ConnectRequest) *rpc
Error: rpc.ConnectInfo_MUST_RESTART,
ClusterContext: s.Kubeconfig.Context,
ClusterServer: s.Kubeconfig.Server,
ClusterId: s.GetClusterId(c),
ManagerInstallId: s.GetManagerInstallId(c),
}
}
Expand Down Expand Up @@ -857,7 +855,6 @@ func (s *session) status(c context.Context, initial bool) *rpc.ConnectInfo {
ret := &rpc.ConnectInfo{
ClusterContext: cfg.Context,
ClusterServer: cfg.Server,
ClusterId: s.GetClusterId(c),
ManagerInstallId: s.GetManagerInstallId(c),
SessionInfo: s.SessionInfo(),
ConnectionName: s.daemonID.Name,
Expand Down
Loading

0 comments on commit b0dc2e3

Please sign in to comment.