Skip to content

Commit

Permalink
Merge pull request #84 from grafana/paul/deprecations
Browse files Browse the repository at this point in the history
Mark old APIs as deprecated
  • Loading branch information
javaducky authored Dec 5, 2022
2 parents 9292ea8 + 1ca4839 commit d629e50
Show file tree
Hide file tree
Showing 12 changed files with 226 additions and 21 deletions.
29 changes: 16 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ This API offers methods for creating, retrieving, listing and deleting resources
The kinds of resources currently supported are:
* ConfigMap
* Deployment
* Ingress
* Job
* Namespace
* Node
Expand Down Expand Up @@ -216,17 +217,19 @@ export default function () {
console.log(`"pod ${pod.metadata.name} not ready after ${timeout} seconds`)
}
}
```
## Resource kind helpers
This API offers a helper for each kind of Kubernetes resources supported (Pods, Deployments, Secrets, et cetera). For each one, an interface for creating, getting, listing and deleting objects is offered.
>⚠️ This interface is deprecated and will be removed soon
>⚠️ This interface is deprecated and will be removed soon
> -
Migrate to the usage of the generic resources API.
</br>
### Create a client: `new Kubernetes(config)`
### (Deprecated) Create a client: `new Kubernetes(config)`
Creates a Kubernetes client to interact with the Kubernetes cluster.
Expand All @@ -244,7 +247,7 @@ export default function () {
}
```
### `Client.config_maps`
### (Deprecated) `Client.config_maps`
| Method | Description | |
| ------------ | ------ | ---------------------------------------- |
Expand All @@ -266,7 +269,7 @@ export default function () {
}
```
### `Client.deployments`
### (Deprecated) `Client.deployments`
| Method | Description | Example |
| ------------ | ------ | ---------------------------------------- |
Expand All @@ -293,7 +296,7 @@ export default function () {
```
### `Client.ingresses`
### (Deprecated) `Client.ingresses`
| Method | Description | |
| ------------ | ------ | ---------------------------------------- |
Expand All @@ -317,7 +320,7 @@ export default function () {
}
```
### `Client.jobs`
### (Deprecated) `Client.jobs`
| Method | Description | Example |
| ------------ | ------ | ---------------------------------------- |
Expand Down Expand Up @@ -354,7 +357,7 @@ export default function () {
}
```
### `Client.namespaces`
### (Deprecated) `Client.namespaces`
| Method | Description | |
| ------------ | ------ | ---------------------------------------- |
Expand All @@ -376,7 +379,7 @@ export default function () {
}
```
### `Client.nodes`
### (Deprecated) `Client.nodes`
| Method | Description | Example |
| ------------ | ------ | ---------------------------------------- |
Expand All @@ -391,7 +394,7 @@ export default function () {
}
```
### `Client.persistent_volumes`
### (Deprecated) `Client.persistent_volumes`
| Method | Description | Example |
| ------------ | ------ | ---------------------------------------- |
Expand All @@ -412,7 +415,7 @@ export default function () {
}
```
### `Client.persistent_volumes_claims`
### (Deprecated) `Client.persistent_volumes_claims`
| Method | Description | Example |
| ------------ | ------ | ---------------------------------------- |
Expand All @@ -435,7 +438,7 @@ export default function () {
}
```
### `Client.pods`
### (Deprecated) `Client.pods`
| Method | Description | Example |
| ------------ | ------ | ---------------------------------------- |
Expand Down Expand Up @@ -480,7 +483,7 @@ export default function () {
}
```
### `Client.secrets`
### (Deprecated) `Client.secrets`
| Method | Description | Example |
| ------------ | ------ | ---------------------------------------- |
Expand All @@ -500,7 +503,7 @@ export default function () {
}
```
### `Client.services`
### (Deprecated) `Client.services`
| Method | Description | Example |
| ------------ | ------ | ---------------------------------------- |
Expand Down
19 changes: 18 additions & 1 deletion pkg/configmaps/configmaps.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// Package configmaps provides implementation of ConfigMap resources for Kubernetes
//
// Deprecated: Use the resources package instead.
package configmaps

import (
Expand All @@ -12,6 +14,8 @@ import (
)

// New creates a new instance backed by the provided client
//
// Deprecated: No longer used.
func New(ctx context.Context, client kubernetes.Interface, metaOptions metav1.ListOptions) *ConfigMaps {
return &ConfigMaps{
client,
Expand All @@ -21,13 +25,17 @@ func New(ctx context.Context, client kubernetes.Interface, metaOptions metav1.Li
}

// ConfigMaps provides API for manipulating ConfigMap resources within a Kubernetes cluster
//
// Deprecated: No longer used in favor of generic resources.
type ConfigMaps struct {
client kubernetes.Interface
metaOptions metav1.ListOptions
ctx context.Context
}

// Apply creates the Kubernetes resource given the supplied YAML configuration
//
// Deprecated: Use resources.Apply instead.
func (obj *ConfigMaps) Apply(yaml string, namespace string) (k8sTypes.ConfigMap, error) {
decode := scheme.Codecs.UniversalDeserializer().Decode
yamlobj, _, err := decode([]byte(yaml), nil, nil)
Expand All @@ -51,6 +59,8 @@ func (obj *ConfigMaps) Apply(yaml string, namespace string) (k8sTypes.ConfigMap,
}

// Create creates the Kubernetes resource given the supplied object
//
// Deprecated: Use resources.Create instead.
func (obj *ConfigMaps) Create(
configMap k8sTypes.ConfigMap,
namespace string,
Expand All @@ -64,6 +74,8 @@ func (obj *ConfigMaps) Create(
}

// List returns a collection of ConfigMaps available within the namespace
//
// Deprecated: Use resources.List instead.
func (obj *ConfigMaps) List(namespace string) ([]k8sTypes.ConfigMap, error) {
cms, err := obj.client.CoreV1().ConfigMaps(namespace).List(obj.ctx, obj.metaOptions)
if err != nil {
Expand All @@ -73,17 +85,22 @@ func (obj *ConfigMaps) List(namespace string) ([]k8sTypes.ConfigMap, error) {
}

// Delete removes the named ConfigMap from the namespace
//
// Deprecated: Use resources.Delete instead.
func (obj *ConfigMaps) Delete(name, namespace string, opts metav1.DeleteOptions) error {
return obj.client.CoreV1().ConfigMaps(namespace).Delete(obj.ctx, name, opts)
}

// Kill removes the named ConfigMap from the namespace
// Deprecated: Use Delete instead.
//
// Deprecated: Use resources.Delete instead.
func (obj *ConfigMaps) Kill(name, namespace string, opts metav1.DeleteOptions) error {
return obj.Delete(name, namespace, opts)
}

// Get returns the named ConfigMaps instance within the namespace if available
//
// Deprecated: Use resources.Get instead.
func (obj *ConfigMaps) Get(name, namespace string, opts metav1.GetOptions) (k8sTypes.ConfigMap, error) {
cm, err := obj.client.CoreV1().ConfigMaps(namespace).Get(obj.ctx, name, opts)
if err != nil {
Expand Down
19 changes: 18 additions & 1 deletion pkg/deployments/deployments.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// Package deployments provides implementation of Deployment resources for Kubernetes
//
// Deprecated: Use the resources package instead.
package deployments

import (
Expand All @@ -12,6 +14,8 @@ import (
)

// New creates a new instance backed by the provided client
//
// Deprecated: No longer used.
func New(ctx context.Context, client kubernetes.Interface, metaOptions metav1.ListOptions) *Deployments {
return &Deployments{
client,
Expand All @@ -21,13 +25,17 @@ func New(ctx context.Context, client kubernetes.Interface, metaOptions metav1.Li
}

// Deployments provides API for manipulating Deployment resources within a Kubernetes cluster
//
// Deprecated: No longer used in favor of generic resources.
type Deployments struct {
client kubernetes.Interface
metaOptions metav1.ListOptions
ctx context.Context
}

// Apply creates the Kubernetes resource given the supplied YAML configuration
//
// Deprecated: Use resources.Apply instead.
func (obj *Deployments) Apply(yaml string, namespace string) (k8sTypes.Deployment, error) {
decode := scheme.Codecs.UniversalDeserializer().Decode
yamlobj, _, err := decode([]byte(yaml), nil, nil)
Expand All @@ -51,6 +59,8 @@ func (obj *Deployments) Apply(yaml string, namespace string) (k8sTypes.Deploymen
}

// Create creates the Kubernetes resource given the supplied object
//
// Deprecated: Use resources.Create instead.
func (obj *Deployments) Create(
deployment k8sTypes.Deployment,
namespace string,
Expand All @@ -64,6 +74,8 @@ func (obj *Deployments) Create(
}

// List returns a collection of Deployments available within the namespace
//
// Deprecated: Use resources.List instead.
func (obj *Deployments) List(namespace string) ([]k8sTypes.Deployment, error) {
dps, err := obj.client.AppsV1().Deployments(namespace).List(obj.ctx, obj.metaOptions)
if err != nil {
Expand All @@ -73,17 +85,22 @@ func (obj *Deployments) List(namespace string) ([]k8sTypes.Deployment, error) {
}

// Delete removes the named Deployment from the namespace
//
// Deprecated: Use resources.Delete instead.
func (obj *Deployments) Delete(name, namespace string, opts metav1.DeleteOptions) error {
return obj.client.AppsV1().Deployments(namespace).Delete(obj.ctx, name, opts)
}

// Kill removes the named Deployment from the namespace
// Deprecated: Use Delete instead.
//
// Deprecated: Use resources.Delete instead.
func (obj *Deployments) Kill(name, namespace string, opts metav1.DeleteOptions) error {
return obj.Delete(name, namespace, opts)
}

// Get returns the named Deployments instance within the namespace if available
//
// Deprecated: Use resources.Get instead.
func (obj *Deployments) Get(name, namespace string, opts metav1.GetOptions) (k8sTypes.Deployment, error) {
dp, err := obj.client.AppsV1().Deployments(namespace).Get(obj.ctx, name, opts)
if err != nil {
Expand Down
19 changes: 18 additions & 1 deletion pkg/ingresses/ingresses.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// Package ingresses provides implementation of Ingress resources for Kubernetes
//
// Deprecated: Use the resources package instead.
package ingresses

import (
Expand All @@ -12,6 +14,8 @@ import (
)

// New creates a new instance backed by the provided client
//
// Deprecated: No longer used.
func New(ctx context.Context, client kubernetes.Interface, metaOptions metav1.ListOptions) *Ingresses {
return &Ingresses{
client,
Expand All @@ -21,13 +25,17 @@ func New(ctx context.Context, client kubernetes.Interface, metaOptions metav1.Li
}

// Ingresses provides API for manipulating Ingress resources within a Kubernetes cluster
//
// Deprecated: No longer used in favor of generic resources.
type Ingresses struct {
client kubernetes.Interface
metaOptions metav1.ListOptions
ctx context.Context
}

// Apply creates the Kubernetes resource given the supplied YAML configuration
//
// Deprecated: Use resources.Apply instead.
func (obj *Ingresses) Apply(yaml string, namespace string) (k8sTypes.Ingress, error) {
decode := scheme.Codecs.UniversalDeserializer().Decode
yamlobj, _, err := decode([]byte(yaml), nil, nil)
Expand All @@ -51,6 +59,8 @@ func (obj *Ingresses) Apply(yaml string, namespace string) (k8sTypes.Ingress, er
}

// Create creates the Kubernetes resource given the supplied object
//
// Deprecated: Use resources.Create instead.
func (obj *Ingresses) Create(
ingress k8sTypes.Ingress,
namespace string,
Expand All @@ -64,6 +74,8 @@ func (obj *Ingresses) Create(
}

// List returns a collection of Ingresses available within the namespace
//
// Deprecated: Use resources.List instead.
func (obj *Ingresses) List(namespace string) ([]k8sTypes.Ingress, error) {
ings, err := obj.client.NetworkingV1().Ingresses(namespace).List(obj.ctx, obj.metaOptions)
if err != nil {
Expand All @@ -73,17 +85,22 @@ func (obj *Ingresses) List(namespace string) ([]k8sTypes.Ingress, error) {
}

// Delete removes the named Ingress from the namespace
//
// Deprecated: Use resources.Delete instead.
func (obj *Ingresses) Delete(name, namespace string, opts metav1.DeleteOptions) error {
return obj.client.NetworkingV1().Ingresses(namespace).Delete(obj.ctx, name, opts)
}

// Kill removes the named Ingress from the namespace
// Deprecated: Use Delete instead.
//
// Deprecated: Use resources.Delete instead.
func (obj *Ingresses) Kill(name, namespace string, opts metav1.DeleteOptions) error {
return obj.Delete(name, namespace, opts)
}

// Get returns the named Ingresses instance within the namespace if available
//
// Deprecated: Use resources.Get instead.
func (obj *Ingresses) Get(name, namespace string, opts metav1.GetOptions) (k8sTypes.Ingress, error) {
ing, err := obj.client.NetworkingV1().Ingresses(namespace).Get(obj.ctx, name, opts)
if err != nil {
Expand Down
Loading

0 comments on commit d629e50

Please sign in to comment.