Skip to content
This repository has been archived by the owner on Dec 15, 2021. It is now read-only.

Commit

Permalink
Use new apps/v1 endpoint (#1087)
Browse files Browse the repository at this point in the history
  • Loading branch information
Andres Martinez Gotor authored Oct 16, 2019
1 parent 1465369 commit 3460f03
Show file tree
Hide file tree
Showing 12 changed files with 84 additions and 84 deletions.
4 changes: 2 additions & 2 deletions cmd/kubeless/function/function.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (
kubelessApi "github.com/kubeless/kubeless/pkg/apis/kubeless/v1beta1"
"github.com/kubeless/kubeless/pkg/client/clientset/versioned"
"github.com/spf13/cobra"
"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
Expand Down Expand Up @@ -359,7 +359,7 @@ func getFunctionDescription(funcName, ns, handler, file, deps, runtime, runtimeI
}

func getDeploymentStatus(cli kubernetes.Interface, funcName, ns string) (string, error) {
dpm, err := cli.ExtensionsV1beta1().Deployments(ns).Get(funcName, metav1.GetOptions{})
dpm, err := cli.AppsV1().Deployments(ns).Get(funcName, metav1.GetOptions{})
if err != nil {
return "", err
}
Expand Down
16 changes: 8 additions & 8 deletions cmd/kubeless/function/function_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ import (
"testing"

kubelessApi "github.com/kubeless/kubeless/pkg/apis/kubeless/v1beta1"
appsv1 "k8s.io/api/apps/v1"
"k8s.io/api/autoscaling/v2beta1"
"k8s.io/api/core/v1"
"k8s.io/api/extensions/v1beta1"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
Expand Down Expand Up @@ -129,8 +129,8 @@ func TestGetFunctionDescription(t *testing.T) {
FunctionContentType: "text",
Deps: "dependencies",
Timeout: "10",
Deployment: v1beta1.Deployment{
Spec: v1beta1.DeploymentSpec{
Deployment: appsv1.Deployment{
Spec: appsv1.DeploymentSpec{
Template: v1.PodTemplateSpec{
Spec: v1.PodSpec{
Containers: []v1.Container{
Expand Down Expand Up @@ -237,8 +237,8 @@ func TestGetFunctionDescription(t *testing.T) {
Checksum: "sha256:1958eb96d7d3cadedd0f327f09322eb7db296afb282ed91aa66cb4ab0dcc3c9f",
Deps: "dependencies2",
Timeout: "20",
Deployment: v1beta1.Deployment{
Spec: v1beta1.DeploymentSpec{
Deployment: appsv1.Deployment{
Spec: appsv1.DeploymentSpec{
Template: v1.PodTemplateSpec{
Spec: v1.PodSpec{
Containers: []v1.Container{
Expand Down Expand Up @@ -401,8 +401,8 @@ func TestGetFunctionDescription(t *testing.T) {
FunctionContentType: "url",
Deps: "dependencies",
Timeout: "10",
Deployment: v1beta1.Deployment{
Spec: v1beta1.DeploymentSpec{
Deployment: appsv1.Deployment{
Spec: appsv1.DeploymentSpec{
Template: v1.PodTemplateSpec{
Spec: v1.PodSpec{
Containers: []v1.Container{
Expand Down
24 changes: 12 additions & 12 deletions cmd/kubeless/function/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import (
"strings"
"testing"

"k8s.io/api/core/v1"
"k8s.io/api/extensions/v1beta1"
appsv1 "k8s.io/api/apps/v1"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
Expand Down Expand Up @@ -58,8 +58,8 @@ func TestList(t *testing.T) {
Function: "ffunction",
Runtime: "fruntime",
Deps: "fdeps",
Deployment: v1beta1.Deployment{
Spec: v1beta1.DeploymentSpec{
Deployment: appsv1.Deployment{
Spec: appsv1.DeploymentSpec{
Template: v1.PodTemplateSpec{
Spec: v1.PodSpec{
Containers: []v1.Container{{}},
Expand All @@ -82,8 +82,8 @@ func TestList(t *testing.T) {
Function: "bfunction",
Runtime: "nodejs6",
Deps: "{\"dependencies\": {\"test\": \"^1.0.0\"}}",
Deployment: v1beta1.Deployment{
Spec: v1beta1.DeploymentSpec{
Deployment: appsv1.Deployment{
Spec: appsv1.DeploymentSpec{
Template: v1.PodTemplateSpec{
Spec: v1.PodSpec{
Containers: []v1.Container{
Expand Down Expand Up @@ -124,8 +124,8 @@ func TestList(t *testing.T) {
Function: "ffunction",
Runtime: "fruntime",
Deps: "fdeps",
Deployment: v1beta1.Deployment{
Spec: v1beta1.DeploymentSpec{
Deployment: appsv1.Deployment{
Spec: appsv1.DeploymentSpec{
Template: v1.PodTemplateSpec{
Spec: v1.PodSpec{
Containers: []v1.Container{{}},
Expand All @@ -140,22 +140,22 @@ func TestList(t *testing.T) {

client := fFake.NewSimpleClientset(listObj.Items[0], listObj.Items[1], listObj.Items[2])

deploymentFoo := v1beta1.Deployment{
deploymentFoo := appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Name: "foo",
Namespace: "myns",
},
Status: v1beta1.DeploymentStatus{
Status: appsv1.DeploymentStatus{
Replicas: int32(1),
ReadyReplicas: int32(1),
},
}
deploymentBar := v1beta1.Deployment{
deploymentBar := appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Name: "bar",
Namespace: "myns",
},
Status: v1beta1.DeploymentStatus{
Status: appsv1.DeploymentStatus{
Replicas: int32(2),
ReadyReplicas: int32(0),
},
Expand Down
20 changes: 10 additions & 10 deletions cmd/kubeless/function/top_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import (
"strings"
"testing"

"k8s.io/api/core/v1"
"k8s.io/api/extensions/v1beta1"
appsv1 "k8s.io/api/apps/v1"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/client-go/kubernetes"
Expand Down Expand Up @@ -280,8 +280,8 @@ func TestTop(t *testing.T) {
Function: function1Name,
Runtime: "pyruntime",
Deps: "pydeps",
Deployment: v1beta1.Deployment{
Spec: v1beta1.DeploymentSpec{
Deployment: appsv1.Deployment{
Spec: appsv1.DeploymentSpec{
Template: v1.PodTemplateSpec{
Spec: v1.PodSpec{
Containers: []v1.Container{{}},
Expand All @@ -301,8 +301,8 @@ func TestTop(t *testing.T) {
Function: function2Name,
Runtime: "goruntime",
Deps: "godeps",
Deployment: v1beta1.Deployment{
Spec: v1beta1.DeploymentSpec{
Deployment: appsv1.Deployment{
Spec: appsv1.DeploymentSpec{
Template: v1.PodTemplateSpec{
Spec: v1.PodSpec{
Containers: []v1.Container{{}},
Expand All @@ -317,22 +317,22 @@ func TestTop(t *testing.T) {

client := fFake.NewSimpleClientset(listObj.Items[0], listObj.Items[1])

deploymentPy := v1beta1.Deployment{
deploymentPy := appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Name: function1Name,
Namespace: namespace,
},
Status: v1beta1.DeploymentStatus{
Status: appsv1.DeploymentStatus{
Replicas: int32(1),
ReadyReplicas: int32(1),
},
}
deploymentGo := v1beta1.Deployment{
deploymentGo := appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Name: function2Name,
Namespace: namespace,
},
Status: v1beta1.DeploymentStatus{
Status: appsv1.DeploymentStatus{
Replicas: int32(1),
ReadyReplicas: int32(1),
},
Expand Down
6 changes: 3 additions & 3 deletions pkg/apis/kubeless/v1beta1/function.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ limitations under the License.
package v1beta1

import (
appsv1 "k8s.io/api/apps/v1"
"k8s.io/api/autoscaling/v2beta1"
"k8s.io/api/core/v1"
"k8s.io/api/extensions/v1beta1"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand All @@ -42,7 +42,7 @@ type FunctionSpec struct {
Runtime string `json:"runtime"` // Function runtime to use
Timeout string `json:"timeout"` // Maximum timeout for the function to complete its execution
Deps string `json:"deps"` // Function dependencies
Deployment v1beta1.Deployment `json:"deployment" protobuf:"bytes,3,opt,name=template"`
Deployment appsv1.Deployment `json:"deployment" protobuf:"bytes,3,opt,name=template"`
ServiceSpec v1.ServiceSpec `json:"service"`
HorizontalPodAutoscaler v2beta1.HorizontalPodAutoscaler `json:"horizontalPodAutoscaler" protobuf:"bytes,3,opt,name=horizontalPodAutoscaler"`
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/function_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ import (

monitoringv1alpha1 "github.com/coreos/prometheus-operator/pkg/client/monitoring/v1alpha1"
"github.com/sirupsen/logrus"
appsv1 "k8s.io/api/apps/v1"
"k8s.io/api/autoscaling/v2beta1"
corev1 "k8s.io/api/core/v1"
"k8s.io/api/extensions/v1beta1"
apiequality "k8s.io/apimachinery/pkg/api/equality"
k8sErrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -300,7 +300,7 @@ func (c *FunctionController) ensureK8sResources(funcObj *kubelessApi.Function) e
}
funcObj.ObjectMeta.Labels["function"] = funcObj.ObjectMeta.Name

deployment := v1beta1.Deployment{}
deployment := appsv1.Deployment{}
if deploymentConfigData, ok := c.config.Data["deployment"]; ok {
err := yaml.Unmarshal([]byte(deploymentConfigData), &deployment)
if err != nil {
Expand Down
27 changes: 13 additions & 14 deletions pkg/controller/function_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ import (
kubelessApi "github.com/kubeless/kubeless/pkg/apis/kubeless/v1beta1"
"github.com/kubeless/kubeless/pkg/langruntime"
"github.com/sirupsen/logrus"
appsv1 "k8s.io/api/apps/v1"
"k8s.io/api/autoscaling/v2beta1"
"k8s.io/api/core/v1"
"k8s.io/api/extensions/v1beta1"
xv1beta1 "k8s.io/api/extensions/v1beta1"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes/fake"
ktesting "k8s.io/client-go/testing"
Expand All @@ -36,7 +35,7 @@ func TestDeleteK8sResources(t *testing.T) {
Name: "foo",
}

deploy := xv1beta1.Deployment{
deploy := appsv1.Deployment{
ObjectMeta: myNsFoo,
}

Expand Down Expand Up @@ -135,11 +134,11 @@ func TestEnsureK8sResourcesWithDeploymentDefinitionFromConfigMap(t *testing.T) {
Deps: "deps",
Handler: "foo.bar",
Runtime: "ruby2.4",
Deployment: v1beta1.Deployment{
Deployment: appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Annotations: funcAnno,
},
Spec: v1beta1.DeploymentSpec{
Spec: appsv1.DeploymentSpec{
Replicas: &replicas,
Template: v1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -209,7 +208,7 @@ func TestEnsureK8sResourcesWithDeploymentDefinitionFromConfigMap(t *testing.T) {
},
Data: map[string]string{"deployment": deploymentConfigData, "runtime-images": string(out)},
}
deploymentObjFromConfigMap := v1beta1.Deployment{}
deploymentObjFromConfigMap := appsv1.Deployment{}
_ = yaml.Unmarshal([]byte(deploymentConfigData), &deploymentObjFromConfigMap)
_, err = clientset.CoreV1().ConfigMaps(namespace).Create(kubelessConfigMap)
if err != nil {
Expand All @@ -233,7 +232,7 @@ func TestEnsureK8sResourcesWithDeploymentDefinitionFromConfigMap(t *testing.T) {
if err := controller.ensureK8sResources(&funcObj); err != nil {
t.Fatalf("Creating/Updating resources returned err: %v", err)
}
dpm, _ := clientset.ExtensionsV1beta1().Deployments(namespace).Get(funcName, metav1.GetOptions{})
dpm, _ := clientset.AppsV1().Deployments(namespace).Get(funcName, metav1.GetOptions{})
expectedAnnotations := map[string]string{
"bar": "foo",
"foo-from-deploy-cm": "bar-from-deploy-cm",
Expand All @@ -248,9 +247,9 @@ func TestEnsureK8sResourcesWithDeploymentDefinitionFromConfigMap(t *testing.T) {
t.Fatalf("Expecting replicas as 10 but received : %d", *dpm.Spec.Replicas)
}
expectedPodAnnotations := map[string]string{
"bar": "foo",
"foo-from-deploy-cm": "bar-from-deploy-cm",
"xyz": "valuefromfunc",
"bar": "foo",
"foo-from-deploy-cm": "bar-from-deploy-cm",
"xyz": "valuefromfunc",
"podannotation-from-func-crd": "value-from-container",
}
for i := range expectedPodAnnotations {
Expand Down Expand Up @@ -284,11 +283,11 @@ func TestEnsureK8sResourcesWithLivenessProbeFromConfigMap(t *testing.T) {
Deps: "deps",
Handler: "foo.bar",
Runtime: "ruby2.4",
Deployment: v1beta1.Deployment{
Deployment: appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Annotations: funcAnno,
},
Spec: v1beta1.DeploymentSpec{
Spec: appsv1.DeploymentSpec{
Replicas: &replicas,
Template: v1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -368,7 +367,7 @@ func TestEnsureK8sResourcesWithLivenessProbeFromConfigMap(t *testing.T) {
if err := controller.ensureK8sResources(&funcObj); err != nil {
t.Fatalf("Creating/Updating resources returned err: %v", err)
}
dpm, _ := clientset.ExtensionsV1beta1().Deployments(namespace).Get(funcName, metav1.GetOptions{})
dpm, _ := clientset.AppsV1().Deployments(namespace).Get(funcName, metav1.GetOptions{})
expectedLivenessProbe := &v1.Probe{
InitialDelaySeconds: int32(5),
PeriodSeconds: int32(10),
Expand Down
6 changes: 3 additions & 3 deletions pkg/langruntime/langruntime.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (

yaml "github.com/ghodss/yaml"
"github.com/sirupsen/logrus"
"k8s.io/api/core/v1"
"k8s.io/api/extensions/v1beta1"
appsv1 "k8s.io/api/apps/v1"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/util/intstr"
)

Expand Down Expand Up @@ -294,7 +294,7 @@ func (l *Langruntimes) GetBuildContainer(runtime, depsChecksum string, env []v1.
}

// UpdateDeployment object in case of custom runtime
func (l *Langruntimes) UpdateDeployment(dpm *v1beta1.Deployment, volPath, runtime string) {
func (l *Langruntimes) UpdateDeployment(dpm *appsv1.Deployment, volPath, runtime string) {
versionInf, err := l.findRuntimeVersion(runtime)
if err != nil {
// Not found an image for the given runtime
Expand Down
8 changes: 4 additions & 4 deletions pkg/utils/k8sutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ import (
kubelessApi "github.com/kubeless/kubeless/pkg/apis/kubeless/v1beta1"
"github.com/sirupsen/logrus"

appsv1 "k8s.io/api/apps/v1"
"k8s.io/api/autoscaling/v2beta1"
"k8s.io/api/core/v1"
"k8s.io/api/extensions/v1beta1"
v1 "k8s.io/api/core/v1"
clientsetAPIExtensions "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
Expand Down Expand Up @@ -347,7 +347,7 @@ func DeleteServiceMonitor(smclient monitoringv1alpha1.MonitoringV1alpha1Client,

// InitializeEmptyMapsInDeployment initializes all nil maps in a Deployment object
// This is done to counteract with side-effects of github.com/imdario/mergo which panics when provided with a nil map in a struct
func initializeEmptyMapsInDeployment(deployment *v1beta1.Deployment) {
func initializeEmptyMapsInDeployment(deployment *appsv1.Deployment) {
if deployment.ObjectMeta.Annotations == nil {
deployment.Annotations = make(map[string]string)
}
Expand All @@ -369,7 +369,7 @@ func initializeEmptyMapsInDeployment(deployment *v1beta1.Deployment) {
}

// MergeDeployments merges two deployment objects
func MergeDeployments(destinationDeployment *v1beta1.Deployment, sourceDeployment *v1beta1.Deployment) error {
func MergeDeployments(destinationDeployment *appsv1.Deployment, sourceDeployment *appsv1.Deployment) error {
// Initializing nil maps in deployment objects else github.com/imdario/mergo panics
initializeEmptyMapsInDeployment(destinationDeployment)
initializeEmptyMapsInDeployment(sourceDeployment)
Expand Down
Loading

0 comments on commit 3460f03

Please sign in to comment.