Skip to content

Commit f92e77f

Browse files
Remove legacy upgrade and it's references (#7309)
With [linkerd2#5008](#5008) and associated PRs, we changed the way configuration is handled by storing a helm values struct inside of the configmap. Now that we have had one stable release with new configuration, were no longer use and need to maintain the legacy config. This commit removes all the associated logic, protobuf files, and references. Changes Include: - Removed [`proto/config/config.proto`](https://github.com/linkerd/linkerd2/blob/main/proto/config/config.proto) - Changed [`bin/protoc-go.sh`](https://github.com/linkerd/linkerd2/blob/main/bin/protoc-go.sh) to not include `config.proto` - Changed [`FetchLinkerdConfigMap()`](https://github.com/linkerd/linkerd2/blob/741fde679b726dd8548765deaf14e7a8c2d2c706/pkg/healthcheck/healthcheck.go#L1768) in `healthcheck.go` to return only the configmap, with the pb type. - Changed [`FetchCurrentConfiguration()`](https://github.com/linkerd/linkerd2/blob/741fde679b726dd8548765deaf14e7a8c2d2c706/pkg/healthcheck/healthcheck.go#L1647) only unmarshal and use helm value struct from configmap (as a follow-up to the todo above; note that there's already a todo here to refactor the function once value struct is the default, which has already happened) - Removed [`upgrade_legacy.go`](https://github.com/linkerd/linkerd2/blob/main/cli/cmd/upgrade_legacy.go) Signed-off-by: Krzysztof Dryś <[email protected]>
1 parent eb2f9e5 commit f92e77f

File tree

14 files changed

+132
-1997
lines changed

14 files changed

+132
-1997
lines changed

bin/protoc-go.sh

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ rm -rf controller/gen/common controller/gen/config viz/metrics-api/gen viz/tap/g
1111
mkdir -p controller/gen/common/net viz/metrics-api/gen/viz viz/tap/gen/tap
1212

1313
"$bindir"/protoc -I proto --go_out=paths=source_relative:controller/gen proto/common/net.proto
14-
"$bindir"/protoc -I proto --go_out=paths=source_relative:controller/gen proto/config/config.proto
1514
"$bindir"/protoc -I proto -I viz/metrics-api/proto --go_out=paths=source_relative:viz/metrics-api/gen viz/metrics-api/proto/viz.proto
1615
"$bindir"/protoc -I proto -I viz/metrics-api/proto --go-grpc_out=paths=source_relative:viz/metrics-api/gen/viz viz/metrics-api/proto/viz.proto
1716
"$bindir"/protoc -I proto -I viz/tap/proto -I viz/metrics-api/proto --go_out=paths=source_relative:viz/tap/gen viz/tap/proto/viz_tap.proto

cli/cmd/repair.go

+77-9
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,13 @@ import (
88
"regexp"
99
"time"
1010

11-
"github.com/golang/protobuf/ptypes"
12-
pb "github.com/linkerd/linkerd2/controller/gen/config"
11+
corev1 "k8s.io/api/core/v1"
12+
"k8s.io/client-go/kubernetes"
13+
1314
"github.com/linkerd/linkerd2/pkg/charts/linkerd2"
15+
charts "github.com/linkerd/linkerd2/pkg/charts/linkerd2"
1416
"github.com/linkerd/linkerd2/pkg/healthcheck"
17+
"github.com/linkerd/linkerd2/pkg/issuercerts"
1518
"github.com/linkerd/linkerd2/pkg/k8s"
1619
"github.com/linkerd/linkerd2/pkg/version"
1720
"github.com/spf13/cobra"
@@ -127,16 +130,16 @@ func repair(ctx context.Context, forced bool) error {
127130
if err != nil {
128131
return fmt.Errorf("Failed to parse IssuanceLifetime from linkerd-config: %s", err)
129132
}
130-
idCtx := pb.IdentityContext{
131-
TrustAnchorsPem: values.IdentityTrustAnchorsPEM,
132-
Scheme: values.Identity.Issuer.Scheme,
133-
ClockSkewAllowance: ptypes.DurationProto(clockSkewDuration),
134-
IssuanceLifetime: ptypes.DurationProto(issuanceLifetime),
135-
TrustDomain: values.IdentityTrustDomain,
133+
idCtx := identityContext{
134+
trustAnchorsPem: values.IdentityTrustAnchorsPEM,
135+
scheme: values.Identity.Issuer.Scheme,
136+
clockSkewAllowance: clockSkewDuration,
137+
issuanceLifetime: issuanceLifetime,
138+
trustDomain: values.IdentityTrustDomain,
136139
}
137140

138141
// Populate identity values
139-
err = fetchIdentityValues(ctx, k8sAPI, &idCtx, &values)
142+
err = fetchIdentityValues(ctx, k8sAPI, idCtx, &values)
140143
if err != nil {
141144
return fmt.Errorf("Failed to load issuer credentials: %s", err)
142145
}
@@ -185,3 +188,68 @@ func resetVersion(values *linkerd2.Values) error {
185188
values.LinkerdVersion = defaults.LinkerdVersion
186189
return nil
187190
}
191+
192+
type identityContext struct {
193+
trustAnchorsPem string
194+
scheme string
195+
clockSkewAllowance time.Duration
196+
issuanceLifetime time.Duration
197+
trustDomain string
198+
}
199+
200+
// fetchIdentityValue checks the kubernetes API to fetch an existing
201+
// linkerd identity configuration.
202+
//
203+
// This bypasses the public API so that we can access secrets and validate
204+
// permissions.
205+
func fetchIdentityValues(ctx context.Context, k kubernetes.Interface, idctx identityContext, values *charts.Values) error {
206+
if idctx.scheme == "" {
207+
// if this is empty, then we are upgrading from a version
208+
// that did not support issuer schemes. Just default to the
209+
// linkerd one.
210+
idctx.scheme = k8s.IdentityIssuerSchemeLinkerd
211+
}
212+
213+
var trustAnchorsPEM string
214+
var issuerData *issuercerts.IssuerCertData
215+
var err error
216+
217+
trustAnchorsPEM = idctx.trustAnchorsPem
218+
219+
issuerData, err = fetchIssuer(ctx, k, trustAnchorsPEM, idctx.scheme)
220+
if err != nil {
221+
return err
222+
}
223+
224+
values.IdentityTrustAnchorsPEM = trustAnchorsPEM
225+
values.Identity.Issuer.Scheme = idctx.scheme
226+
values.Identity.Issuer.ClockSkewAllowance = idctx.clockSkewAllowance.String()
227+
values.Identity.Issuer.IssuanceLifetime = idctx.issuanceLifetime.String()
228+
values.Identity.Issuer.TLS.KeyPEM = issuerData.IssuerKey
229+
values.Identity.Issuer.TLS.CrtPEM = issuerData.IssuerCrt
230+
231+
return nil
232+
}
233+
234+
func fetchIssuer(ctx context.Context, k kubernetes.Interface, trustPEM string, scheme string) (*issuercerts.IssuerCertData, error) {
235+
var (
236+
issuerData *issuercerts.IssuerCertData
237+
err error
238+
)
239+
switch scheme {
240+
case string(corev1.SecretTypeTLS):
241+
// Do not return external issuer certs as no need of storing them in config and upgrade secrets
242+
// Also contradicts condition in https://github.com/linkerd/linkerd2/blob/main/cli/cmd/options.go#L550
243+
return &issuercerts.IssuerCertData{}, nil
244+
default:
245+
issuerData, err = issuercerts.FetchIssuerData(ctx, k, trustPEM, controlPlaneNamespace)
246+
if issuerData != nil && issuerData.TrustAnchors != trustPEM {
247+
issuerData.TrustAnchors = trustPEM
248+
}
249+
}
250+
if err != nil {
251+
return nil, err
252+
}
253+
254+
return issuerData, nil
255+
}

cli/cmd/upgrade.go

+3-12
Original file line numberDiff line numberDiff line change
@@ -265,19 +265,10 @@ func upgrade(ctx context.Context, k *k8s.KubernetesAPI, flags []flag.Flag, stage
265265
if err != nil {
266266
return bytes.Buffer{}, fmt.Errorf("failed to load stored values: %w", err)
267267
}
268-
// If there is no linkerd-config-overrides secret, assume we are upgrading
269-
// from a version of Linkerd prior to the introduction of this secret. In
270-
// this case we load the values from the legacy linkerd-config configmap.
271-
if values == nil {
272-
values, err = loadStoredValuesLegacy(ctx, k)
273-
if err != nil {
274-
return bytes.Buffer{}, err
275-
}
276-
}
277268

278-
// If values is still nil, then neither the linkerd-config-overrides secret
279-
// nor the legacy values were found. This means either means that Linkerd
280-
// was installed with Helm or that the installation needs to be repaired.
269+
// If values is still nil, then the linkerd-config-overrides secret was not found.
270+
// This means either means that Linkerd was installed with Helm or that the installation
271+
// needs to be repaired.
281272
if values == nil {
282273
return bytes.Buffer{}, errors.New(
283274
`Could not find the Linkerd config. If Linkerd was installed with Helm, please

cli/cmd/upgrade_legacy.go

-183
This file was deleted.

controller/api/destination/watcher/opaque_ports_watcher.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,7 @@ func getServiceOpaquePortsAnnotation(svc *corev1.Service) (map[uint32]struct{},
203203
func parseServiceOpaquePorts(annotation string, sps []corev1.ServicePort) []string {
204204
portRanges := util.GetPortRanges(annotation)
205205
var values []string
206-
for _, portRange := range portRanges {
207-
pr := portRange.GetPortRange()
206+
for _, pr := range portRanges {
208207
port, named := isNamed(pr, sps)
209208
if named {
210209
values = append(values, strconv.Itoa(int(port)))

0 commit comments

Comments
 (0)