-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract PodControllerProcessor interface and default implementation (#…
…2297) * Extract PodControllerProcessor interface and default implementation * Extract PodCommandExecutorProcessor interface and default implementation * Extract PodFileWriterProcessor interface and default implementation * Apply suggestions from code review - copyright header Co-authored-by: Pavan Navarathna <6504783+pavannd1@users.noreply.github.com> * Apply suggestions from code review - metav1 Co-authored-by: Pavan Navarathna <6504783+pavannd1@users.noreply.github.com> --------- Co-authored-by: Pavan Navarathna <6504783+pavannd1@users.noreply.github.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
- Loading branch information
1 parent
f93f456
commit dbae8b8
Showing
11 changed files
with
159 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Copyright 2023 The Kanister 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 kube | ||
|
||
import ( | ||
"k8s.io/client-go/kubernetes" | ||
) | ||
|
||
// PodCommandExecutorProcessor is an interface wrapping kubernetes API invocation | ||
// it is purposed to be replaced by fake implementation in tests | ||
type PodCommandExecutorProcessor interface { | ||
ExecWithOptions(opts ExecOptions) (string, string, error) | ||
} | ||
|
||
type podCommandExecutorProcessor struct { | ||
cli kubernetes.Interface | ||
} | ||
|
||
// ExecWithOptions executes a command in the specified pod and container, | ||
// returning stdout, stderr and error. | ||
func (p *podCommandExecutorProcessor) ExecWithOptions(opts ExecOptions) (string, string, error) { | ||
return ExecWithOptions(p.cli, opts) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright 2023 The Kanister 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 kube | ||
|
||
import ( | ||
"context" | ||
|
||
"k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/client-go/kubernetes" | ||
) | ||
|
||
// PodControllerProcessor is an interface wrapping kubernetes API invocation | ||
// it is purposed to be replaced by fake implementation in tests | ||
type PodControllerProcessor interface { | ||
CreatePod(ctx context.Context, options *PodOptions) (*v1.Pod, error) | ||
WaitForPodReady(ctx context.Context, namespace, podName string) error | ||
WaitForPodCompletion(ctx context.Context, namespace, podName string) error | ||
DeletePod(ctx context.Context, namespace string, podName string, opts metav1.DeleteOptions) error | ||
} | ||
|
||
type podControllerProcessor struct { | ||
cli kubernetes.Interface | ||
} | ||
|
||
func (p *podControllerProcessor) CreatePod(ctx context.Context, options *PodOptions) (*v1.Pod, error) { | ||
return CreatePod(ctx, p.cli, options) | ||
} | ||
|
||
func (p *podControllerProcessor) WaitForPodReady(ctx context.Context, namespace, podName string) error { | ||
return WaitForPodReady(ctx, p.cli, namespace, podName) | ||
} | ||
|
||
func (p *podControllerProcessor) WaitForPodCompletion(ctx context.Context, namespace, podName string) error { | ||
return WaitForPodCompletion(ctx, p.cli, namespace, podName) | ||
} | ||
|
||
func (p *podControllerProcessor) DeletePod(ctx context.Context, namespace string, podName string, opts metav1.DeleteOptions) error { | ||
return p.cli.CoreV1().Pods(namespace).Delete(ctx, podName, opts) | ||
} |
Oops, something went wrong.