-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adjust snap.Interface to return Kubernetes clients (#384)
* move pkg/utils/k8s -> pkg/client/kubernetes * adjust snap to return Kubernetes clients instead of config flags * Move helm client logic to pkg/client/helm package * adjust snap interface to return a HelmClient * add unit test for features.ApplyMetricsServer
- Loading branch information
1 parent
ea6b8fc
commit 7cd6466
Showing
46 changed files
with
371 additions
and
295 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package helm | ||
|
||
// InstallableChart describes a chart that can be deployed on a running cluster. | ||
type InstallableChart struct { | ||
// Name is the install name of the chart. | ||
Name string | ||
|
||
// Namespace is the namespace to install the chart. | ||
Namespace string | ||
|
||
// ManifestPath is the path to the chart's manifest, typically relative to "$SNAP/k8s/manifests". | ||
// TODO(neoaggelos): this should be a *chart.Chart, and we should use the "embed" package to load it when building k8sd. | ||
ManifestPath string | ||
} |
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,13 @@ | ||
package helm | ||
|
||
import "context" | ||
|
||
// Client handles the lifecycle of charts (manifests + config) on the cluster. | ||
type Client interface { | ||
// Apply ensures the state of a InstallableChart on the cluster. | ||
// When state is StatePresent, Apply will install or upgrade the chart using the specified values as configuration. Apply returns true if the chart was not installed, or any values were changed. | ||
// When state is StateUpgradeOnly, Apply will upgrade the chart using the specified values as configuration. Apply returns true if the chart was not installed, or any values were changed. An error is returned if the chart is not already installed. | ||
// When state is StateDeleted, Apply will ensure that the chart is removed. If the chart is not installed, this is a no-op. Apply returns true if the chart was previously installed. | ||
// Apply returns an error in case of failure. | ||
Apply(ctx context.Context, f InstallableChart, desired State, values map[string]any) (bool, error) | ||
} |
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,29 @@ | ||
package mock | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/canonical/k8s/pkg/client/helm" | ||
) | ||
|
||
type MockApplyArguments struct { | ||
Context context.Context | ||
Chart helm.InstallableChart | ||
State helm.State | ||
Values map[string]any | ||
} | ||
|
||
// Mock is a mock implementation of helm.Client | ||
type Mock struct { | ||
ApplyCalledWith []MockApplyArguments | ||
ApplyChanged bool | ||
ApplyErr error | ||
} | ||
|
||
// Apply implements helm.Client | ||
func (m *Mock) Apply(ctx context.Context, c helm.InstallableChart, desired helm.State, values map[string]any) (bool, error) { | ||
m.ApplyCalledWith = append(m.ApplyCalledWith, MockApplyArguments{Context: ctx, Chart: c, State: desired, Values: values}) | ||
return m.ApplyChanged, m.ApplyErr | ||
} | ||
|
||
var _ helm.Client = &Mock{} |
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,29 @@ | ||
package helm | ||
|
||
// State is used to define how Client.Apply() handles install, upgrade or delete operations. | ||
type State int | ||
|
||
const ( | ||
// StateDeleted means that the chart should not be installed. | ||
StateDeleted State = iota | ||
|
||
// StatePresent means that the chart must be present. If it already exists, it is upgraded with the new configuration, otherwise it is installed. | ||
StatePresent | ||
|
||
// StateUpgradeOnly means that the chart will be refreshed if installed, fail otherwise. | ||
StateUpgradeOnly | ||
) | ||
|
||
func StatePresentOrDeleted(enabled bool) State { | ||
if enabled { | ||
return StatePresent | ||
} | ||
return StateDeleted | ||
} | ||
|
||
func StateUpgradeOnlyOrDeleted(enabled bool) State { | ||
if enabled { | ||
return StateUpgradeOnly | ||
} | ||
return StateDeleted | ||
} |
2 changes: 1 addition & 1 deletion
2
src/k8s/pkg/utils/k8s/client.go → src/k8s/pkg/client/kubernetes/client.go
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package k8s | ||
package kubernetes | ||
|
||
import ( | ||
"fmt" | ||
|
2 changes: 1 addition & 1 deletion
2
src/k8s/pkg/utils/k8s/configmap.go → src/k8s/pkg/client/kubernetes/configmap.go
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package k8s | ||
package kubernetes | ||
|
||
import ( | ||
"context" | ||
|
2 changes: 1 addition & 1 deletion
2
src/k8s/pkg/utils/k8s/configmap_test.go → ...s/pkg/client/kubernetes/configmap_test.go
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package k8s | ||
package kubernetes | ||
|
||
import ( | ||
"context" | ||
|
2 changes: 1 addition & 1 deletion
2
src/k8s/pkg/utils/k8s/endpoints.go → src/k8s/pkg/client/kubernetes/endpoints.go
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package k8s | ||
package kubernetes | ||
|
||
import ( | ||
"context" | ||
|
2 changes: 1 addition & 1 deletion
2
src/k8s/pkg/utils/k8s/endpoints_test.go → ...s/pkg/client/kubernetes/endpoints_test.go
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package k8s | ||
package kubernetes | ||
|
||
import ( | ||
"context" | ||
|
2 changes: 1 addition & 1 deletion
2
src/k8s/pkg/utils/k8s/node.go → src/k8s/pkg/client/kubernetes/node.go
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package k8s | ||
package kubernetes | ||
|
||
import ( | ||
"context" | ||
|
2 changes: 1 addition & 1 deletion
2
src/k8s/pkg/utils/k8s/node_test.go → src/k8s/pkg/client/kubernetes/node_test.go
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package k8s | ||
package kubernetes | ||
|
||
import ( | ||
"context" | ||
|
2 changes: 1 addition & 1 deletion
2
src/k8s/pkg/utils/k8s/restart_daemonset.go → ...kg/client/kubernetes/restart_daemonset.go
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package k8s | ||
package kubernetes | ||
|
||
import ( | ||
"context" | ||
|
2 changes: 1 addition & 1 deletion
2
...s/pkg/utils/k8s/restart_daemonset_test.go → ...ient/kubernetes/restart_daemonset_test.go
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package k8s | ||
package kubernetes | ||
|
||
import ( | ||
"context" | ||
|
2 changes: 1 addition & 1 deletion
2
src/k8s/pkg/utils/k8s/restart_deployment.go → ...g/client/kubernetes/restart_deployment.go
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package k8s | ||
package kubernetes | ||
|
||
import ( | ||
"context" | ||
|
2 changes: 1 addition & 1 deletion
2
.../pkg/utils/k8s/restart_deployment_test.go → ...ent/kubernetes/restart_deployment_test.go
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package k8s | ||
package kubernetes | ||
|
||
import ( | ||
"context" | ||
|
2 changes: 1 addition & 1 deletion
2
src/k8s/pkg/utils/k8s/server_groups.go → ...8s/pkg/client/kubernetes/server_groups.go
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package k8s | ||
package kubernetes | ||
|
||
import ( | ||
"fmt" | ||
|
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
2 changes: 1 addition & 1 deletion
2
src/k8s/pkg/utils/k8s/services.go → src/k8s/pkg/client/kubernetes/services.go
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package k8s | ||
package kubernetes | ||
|
||
import ( | ||
"context" | ||
|
2 changes: 1 addition & 1 deletion
2
src/k8s/pkg/utils/k8s/services_test.go → ...8s/pkg/client/kubernetes/services_test.go
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package k8s | ||
package kubernetes | ||
|
||
import ( | ||
"context" | ||
|
2 changes: 1 addition & 1 deletion
2
src/k8s/pkg/utils/k8s/status.go → src/k8s/pkg/client/kubernetes/status.go
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package k8s | ||
package kubernetes | ||
|
||
import ( | ||
"context" | ||
|
2 changes: 1 addition & 1 deletion
2
src/k8s/pkg/utils/k8s/status_test.go → src/k8s/pkg/client/kubernetes/status_test.go
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package k8s | ||
package kubernetes | ||
|
||
import ( | ||
"context" | ||
|
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
Oops, something went wrong.