diff --git a/changelog/rm-pkg-ready.yaml b/changelog/rm-pkg-ready.yaml new file mode 100644 index 00000000000..5f98bedb5b8 --- /dev/null +++ b/changelog/rm-pkg-ready.yaml @@ -0,0 +1,14 @@ +# entries is a list of entries to include in +# release notes and/or the migration guide +entries: + - description: > + Removed `pkg/ready` and its helper utils `Ready`, `Set()`, `Unset()`. + + kind: "removal" + + breaking: true + + migration: + header: Removed `pkg/ready` + body: > + TBD diff --git a/pkg/ready/ready.go b/pkg/ready/ready.go deleted file mode 100644 index 8cd04707600..00000000000 --- a/pkg/ready/ready.go +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright 2018 The Operator-SDK Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package ready - -import ( - "os" -) - -// FileName represent the full path to the file for determining ready status -const FileName = "/tmp/operator-sdk-ready" - -// Ready holds state about whether the operator is ready and communicates that -// to a Kubernetes readiness probe. -type Ready interface { - // Set ensures that future readiness probes will indicate that the operator - // is ready. - Set() error - - // Unset ensures that future readiness probes will indicate that the - // operator is not ready. - Unset() error -} - -// NewFileReady returns a Ready that uses the presence of a file on disk to -// communicate whether the operator is ready. The operator's Pod definition -// should include a readinessProbe of "exec" type that calls -// "stat /tmp/operator-sdk-ready". -func NewFileReady() Ready { - return fileReady{} -} - -type fileReady struct{} - -// Set creates a file on disk whose presence can be used by a readiness probe -// to determine that the operator is ready. -func (r fileReady) Set() error { - f, err := os.Create(FileName) - if err != nil { - if os.IsExist(err) { - return nil - } - return err - } - return f.Close() -} - -// Unset removes the file on disk that was created by Set(). -func (r fileReady) Unset() error { - if _, err := os.Stat(FileName); os.IsNotExist(err) { - return nil - } - return os.Remove(FileName) -} diff --git a/pkg/ready/ready_test.go b/pkg/ready/ready_test.go deleted file mode 100644 index 77a4904a187..00000000000 --- a/pkg/ready/ready_test.go +++ /dev/null @@ -1,71 +0,0 @@ -// Copyright 2018 The Operator-SDK Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package ready - -import ( - "os" - "testing" -) - -func TestFileReady(t *testing.T) { - r := NewFileReady() - err := r.Set() - if err != nil { - t.Errorf("Could not set ready file: %v", err) - } - - _, err = os.Stat(FileName) - if err != nil { - t.Errorf("Did not find expected file at %s: %v", FileName, err) - } - - // Should be safe to set multiple times - err = r.Set() - if err != nil { - t.Errorf("Failed to set ready file when it already exists: %v", err) - } - - err = r.Unset() - if err != nil { - t.Errorf("Could not unset ready file: %v", err) - } - - _, err = os.Stat(FileName) - if err == nil { - t.Errorf("File still exists at %s", FileName) - } - if !os.IsNotExist(err) { - t.Errorf("Error determining if file still exists at %s: %v", FileName, err) - } - - err = r.Unset() - if err != nil { - t.Errorf("Could not unset ready file when already removed: %v", err) - } -} - -func TestAlreadyExistsNoError(t *testing.T) { - f, err := os.Create(FileName) - if err != nil { - t.Errorf("Could not create test ready file: %v", err) - } - defer f.Close() - - r := NewFileReady() - err = r.Set() - if err != nil { - t.Errorf("Could not set ready file: %v", err) - } -}