Skip to content

Commit 864b3c6

Browse files
committed
HIVE-2781: nix terminateWhenFilesChange()
We used to mount credentials Secrets on deprovision pods. When we were doing that, if the Secret changed, the data in the mounted directory would get updated dynamically by kube. We had code in place to terminate the deprovision command in that scenario, since it would presumably fail 401 the next time it needed to create a cloud client. Via HIVE-2021 / #1874 / 0f4b1de we stopped with the mounting, and started loading the Secrets explicitly from the deprovision pods. Although we're still laying the data down in the same kind of directory structure, it is no longer possible for the values to change dynamically. This renders the aforementioned code obsolete. So we're ripping it out. HIVE-2781
1 parent 9b3202b commit 864b3c6

File tree

6 files changed

+0
-376
lines changed

6 files changed

+0
-376
lines changed

contrib/pkg/deprovision/awstagdeprovision.go

-4
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,6 @@ func NewDeprovisionAWSWithTagsCommand() *cobra.Command {
2828
return
2929
}
3030

31-
if credsDir != "" {
32-
go terminateWhenFilesChange(credsDir)
33-
}
34-
3531
log.Infof("Running destroyer with ClusterUninstall %#v", *opt)
3632
// ClusterQuota stomped in return
3733
if _, err := opt.Run(); err != nil {
-62
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,7 @@
11
package deprovision
22

33
import (
4-
"os"
5-
"path/filepath"
6-
"time"
7-
8-
"github.com/pkg/errors"
9-
log "github.com/sirupsen/logrus"
104
"github.com/spf13/cobra"
11-
12-
"github.com/openshift/library-go/pkg/controller/fileobserver"
135
)
146

157
// NewDeprovisionCommand is the entrypoint to create the 'deprovision' subcommand
@@ -21,12 +13,6 @@ func NewDeprovisionCommand() *cobra.Command {
2113
Run: func(cmd *cobra.Command, args []string) {
2214
cmd.Usage()
2315
},
24-
PersistentPreRun: func(cmd *cobra.Command, args []string) {
25-
if credsDir == "" {
26-
return
27-
}
28-
go terminateWhenFilesChange(credsDir)
29-
},
3016
}
3117
flags := cmd.PersistentFlags()
3218
flags.StringVar(&credsDir, "creds-dir", "", "directory of the creds. Changes in the creds will cause the program to terminate")
@@ -38,51 +24,3 @@ func NewDeprovisionCommand() *cobra.Command {
3824
cmd.AddCommand(NewDeprovisionOvirtCommand())
3925
return cmd
4026
}
41-
42-
func terminateWhenFilesChange(dir string) {
43-
fileContents := map[string][]byte{}
44-
var filenames []string
45-
if err := filepath.Walk(
46-
dir,
47-
func(path string, info os.FileInfo, err error) error {
48-
if err != nil {
49-
return errors.Wrapf(err, "problem encountered walking %s", path)
50-
}
51-
if info.IsDir() {
52-
// skip directories
53-
return nil
54-
}
55-
if info.Mode()&os.ModeSymlink != 0 {
56-
// skip symlinks
57-
return nil
58-
}
59-
data, err := os.ReadFile(path)
60-
if err != nil {
61-
return errors.Wrapf(err, "could not read contents of %s", path)
62-
}
63-
fileContents[path] = data
64-
filenames = append(filenames, path)
65-
return nil
66-
},
67-
); err != nil {
68-
log.WithError(err).Fatal("could not read files for creds watch")
69-
}
70-
obs, err := fileobserver.NewObserver(10 * time.Second)
71-
if err != nil {
72-
log.WithError(err).Fatal("could not set up file observer for creds watch")
73-
}
74-
obs.AddReactor(
75-
func(filename string, action fileobserver.ActionType) error {
76-
log.WithField("filename", filename).Fatal("exiting because creds file changed")
77-
return nil
78-
},
79-
fileContents,
80-
filenames...,
81-
)
82-
stop := make(chan struct{})
83-
go func() {
84-
log.WithField("files", filenames).Info("running file observer")
85-
obs.Run(stop)
86-
log.Fatal("file observer stopped")
87-
}()
88-
}

vendor/github.com/openshift/library-go/pkg/controller/fileobserver/OWNERS

-6
This file was deleted.

vendor/github.com/openshift/library-go/pkg/controller/fileobserver/observer.go

-80
This file was deleted.

0 commit comments

Comments
 (0)