• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

operator-framework / operator-sdk / 12323500562

13 Dec 2024 09:44PM UTC coverage: 34.569%. First build
12323500562

Pull #6878

github

acornett21
k8s 1.31 work

Signed-off-by: Adam D. Cornett <adc@redhat.com>
Pull Request #6878: k8s 1.31 work

9 of 22 new or added lines in 15 files covered. (40.91%)

4766 of 13787 relevant lines covered (34.57%)

13.62 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/internal/cmd/operator-sdk/alpha/config3alphato3/cmd.go
1
// Copyright 2021 The Operator-SDK Authors
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
//     http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14

15
package config3alphato3
16

17
import (
18
        "fmt"
19
        "os"
20

21
        log "github.com/sirupsen/logrus"
22
        "github.com/spf13/cobra"
23
        "sigs.k8s.io/yaml"
24
)
25

26
func NewCmd() *cobra.Command {
×
27
        return &cobra.Command{
×
28
                Use:   "config-3alpha-to-3",
×
29
                Short: "Convert your PROJECT config file from version 3-alpha to 3",
×
30
                Long: `Your PROJECT file contains config data specified by some version.
×
31
This version is not a kubernetes-style version. In general, alpha and beta config versions
×
32
are unstable and support for them is dropped once a stable version is released.
×
33
The 3-alpha version has recently become stable (3), and therefore is no longer
×
34
supported by operator-sdk v1.5+. This command is intended to migrate 3-alpha PROJECT files
×
35
to 3 with as few manual modifications required as possible.
×
36
`,
×
NEW
37
                RunE: func(_ *cobra.Command, _ []string) (err error) {
×
38
                        cfgBytes, err := os.ReadFile("PROJECT")
×
39
                        if err != nil {
×
40
                                return fmt.Errorf("%v (config-3alpha-to-3 must be run from project root)", err)
×
41
                        }
×
42

43
                        if ver, err := getConfigVersion(cfgBytes); err == nil && ver != v3alpha {
×
44
                                fmt.Println("Your PROJECT config file is not convertible at version", ver)
×
45
                                return nil
×
46
                        }
×
47

48
                        b, err := convertConfig3AlphaTo3(cfgBytes)
×
49
                        if err != nil {
×
50
                                return err
×
51
                        }
×
52
                        if err := os.WriteFile("PROJECT", b, 0666); err != nil {
×
53
                                return err
×
54
                        }
×
55

56
                        fmt.Println("Your PROJECT config file has been converted from version 3-alpha to 3. " +
×
57
                                "Please make sure all config data is correct.")
×
58

×
59
                        return nil
×
60
                },
61
        }
62
}
63

64
// RootPersistentPreRun prints a helpful message on any exit caused by kubebuilder's
65
// config unmarshal step finding "3-alpha", since the CLI will not recognize this version.
66
// Add this to the root command (`operator-sdk`).
NEW
67
var RootPersistentPreRun = func(_ *cobra.Command, _ []string) {
×
68
        if cfgBytes, err := os.ReadFile("PROJECT"); err == nil {
×
69
                if ver, err := getConfigVersion(cfgBytes); err == nil && ver == v3alpha {
×
70
                        log.Warn("Config version 3-alpha has been stabilized as 3, and 3-alpha is no longer supported. " +
×
71
                                "Run `operator-sdk alpha config-3alpha-to-3` to upgrade your PROJECT config file to version 3",
×
72
                        )
×
73
                }
×
74
        }
75
}
76

77
func getConfigVersion(b []byte) (string, error) {
×
78
        var verObj struct {
×
79
                Version string `json:"version"`
×
80
        }
×
81
        return verObj.Version, yaml.Unmarshal(b, &verObj)
×
82
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc