From f687fe55265146c7de655f7fcb8d339a47e8786c Mon Sep 17 00:00:00 2001 From: Micah Wylde Date: Tue, 6 Aug 2019 16:54:58 -0700 Subject: [PATCH] [STRMCMP-590] Update CRD version to v1beta1 (#67) Update CRD version to v1beta1 --- README.md | 5 +- config/config.yaml | 2 +- deploy/crd.yaml | 2 +- deploy/flinkk8soperator.yaml | 4 +- docs/crd.md | 4 +- docs/quick-start-guide.md | 4 +- .../flink-operator-custom-resource.yaml | 2 +- integ/checkpoint_failure_test.go | 6 +- integ/simple_test.go | 38 +- integ/test_app.yaml | 2 +- integ/utils/utils.go | 20 +- ...eme_v1alpha1.go => addtoscheme_v1beta1.go} | 4 +- pkg/apis/app/v1beta1/doc.go | 3 + pkg/apis/app/v1beta1/register.go | 42 +++ pkg/apis/app/v1beta1/types.go | 267 ++++++++++++++ pkg/apis/app/v1beta1/zz_generated.deepcopy.go | 337 ++++++++++++++++++ pkg/client/clientset/versioned/clientset.go | 18 +- .../versioned/fake/clientset_generated.go | 10 +- .../clientset/versioned/fake/register.go | 4 +- .../clientset/versioned/scheme/register.go | 4 +- .../versioned/typed/app/v1beta1/app_client.go | 74 ++++ .../versioned/typed/app/v1beta1/doc.go | 4 + .../versioned/typed/app/v1beta1/fake/doc.go | 4 + .../typed/app/v1beta1/fake/fake_app_client.go | 24 ++ .../app/v1beta1/fake/fake_flinkapplication.go | 112 ++++++ .../typed/app/v1beta1/flinkapplication.go | 158 ++++++++ .../typed/app/v1beta1/generated_expansion.go | 5 + pkg/controller/flink/config.go | 30 +- pkg/controller/flink/config_test.go | 32 +- pkg/controller/flink/container_utils.go | 16 +- pkg/controller/flink/container_utils_test.go | 8 +- pkg/controller/flink/flink.go | 84 ++--- pkg/controller/flink/flink_test.go | 50 +-- pkg/controller/flink/ingress.go | 4 +- .../flink/job_manager_controller.go | 26 +- .../flink/job_manager_controller_test.go | 4 +- pkg/controller/flink/mock/mock_flink.go | 56 +-- .../flink/mock/mock_job_manager_controller.go | 4 +- .../mock/mock_task_manager_controller.go | 6 +- .../flink/task_manager_controller.go | 22 +- .../flink/task_manager_controller_test.go | 4 +- pkg/controller/flinkapplication/controller.go | 14 +- .../flinkapplication/flink_state_machine.go | 104 +++--- .../flink_state_machine_test.go | 320 ++++++++--------- tmp/codegen/update-generated.sh | 2 +- version/version.go | 2 +- 46 files changed, 1489 insertions(+), 458 deletions(-) rename pkg/apis/app/{addtoscheme_v1alpha1.go => addtoscheme_v1beta1.go} (60%) create mode 100644 pkg/apis/app/v1beta1/doc.go create mode 100644 pkg/apis/app/v1beta1/register.go create mode 100644 pkg/apis/app/v1beta1/types.go create mode 100644 pkg/apis/app/v1beta1/zz_generated.deepcopy.go create mode 100644 pkg/client/clientset/versioned/typed/app/v1beta1/app_client.go create mode 100644 pkg/client/clientset/versioned/typed/app/v1beta1/doc.go create mode 100644 pkg/client/clientset/versioned/typed/app/v1beta1/fake/doc.go create mode 100644 pkg/client/clientset/versioned/typed/app/v1beta1/fake/fake_app_client.go create mode 100644 pkg/client/clientset/versioned/typed/app/v1beta1/fake/fake_flinkapplication.go create mode 100644 pkg/client/clientset/versioned/typed/app/v1beta1/flinkapplication.go create mode 100644 pkg/client/clientset/versioned/typed/app/v1beta1/generated_expansion.go diff --git a/README.md b/README.md index ec745fe0..41a934e3 100644 --- a/README.md +++ b/README.md @@ -14,9 +14,10 @@ FlinkK8sOperator is a [Kubernetes operator](https://coreos.com/operators/) that ## Project Status -*Alpha* +*Beta* -The FlinkK8sOperator is still under active development and has not been extensively tested in production environment. Backward compatibility of the APIs is not guaranteed for alpha releases. +The operator is in use for some less-crtical jobs at Lyft. At this point the focus is on testing and stability While in +Beta, we will attempt to limit the number of backwards-incompatible changes, but they may still occur as necessary. ## Prerequisites * Version >= 1.9 of Kubernetes. diff --git a/config/config.yaml b/config/config.yaml index 1358c3cc..371f0756 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -1,3 +1,3 @@ -apiVersion: flink.k8s.io/v1alpha1 +apiVersion: flink.k8s.io/v1beta1 kind: FlinkApplication projectName: flinkk8soperator diff --git a/deploy/crd.yaml b/deploy/crd.yaml index 2a78ccb7..b59c82d5 100644 --- a/deploy/crd.yaml +++ b/deploy/crd.yaml @@ -12,7 +12,7 @@ spec: shortNames: - flinkapp scope: Namespaced - version: v1alpha1 + version: v1beta1 validation: # openAPIV3Schema is the schema for validating custom objects. openAPIV3Schema: diff --git a/deploy/flinkk8soperator.yaml b/deploy/flinkk8soperator.yaml index 7355062a..59062c74 100644 --- a/deploy/flinkk8soperator.yaml +++ b/deploy/flinkk8soperator.yaml @@ -14,7 +14,7 @@ spec: metadata: labels: app: flinkoperator - app.kubernetes.io/version: 0.1.3 + app.kubernetes.io/version: 0.2.0 spec: serviceAccountName: flinkoperator volumes: @@ -26,7 +26,7 @@ spec: path: config.yaml containers: - name: flinkoperator-gojson - image: docker.io/lyft/flinkk8soperator:v0.1.3 + image: docker.io/lyft/flinkk8soperator:v0.2.0 command: - flinkoperator args: diff --git a/docs/crd.md b/docs/crd.md index f4544e91..2c45e67f 100644 --- a/docs/crd.md +++ b/docs/crd.md @@ -3,7 +3,7 @@ The [flinkapplication](https://github.com/lyft/flinkk8soperator/blob/master/depl [FlinkApplication Custom Resource Example](https://github.com/lyft/flinkk8soperator/blob/master/examples/wordcount/flink-operator-custom-resource.yaml) -The type information is available here [FlinkApplication Type](https://github.com/lyft/flinkk8soperator/blob/master/pkg/apis/app/v1alpha1/types.go#L25) +The type information is available here [FlinkApplication Type](https://github.com/lyft/flinkk8soperator/blob/master/pkg/apis/app/v1beta1/types.go#L25) Below is the list of fields in the custom resource and their description @@ -111,4 +111,4 @@ Below is the list of fields in the custom resource and their description * **ForceRollback** `type:bool` Can be set to true to force rollback a deploy/update. The rollback is **not** performed when the application is in a **RUNNING** phase. If an application is successfully rolled back, it is moved to a *DeployFailed* phase. Un-setting or setting `ForceRollback` to `False` will allow updates to progress normally. - \ No newline at end of file + diff --git a/docs/quick-start-guide.md b/docs/quick-start-guide.md index 36aeae9c..0e684adb 100644 --- a/docs/quick-start-guide.md +++ b/docs/quick-start-guide.md @@ -85,7 +85,7 @@ $ kubectl get flinkapplication.flink.k8s.io -n flink-operator wordcount-operator The output should be something like this ```yaml -apiVersion: flink.k8s.io/v1alpha1 +apiVersion: v1beta1 kind: FlinkApplication metadata: clusterName: "" @@ -98,7 +98,7 @@ metadata: name: wordcount-operator-example namespace: flink-operator resourceVersion: "1025774" - selfLink: /apis/flink.k8s.io/v1alpha1/namespaces/flink-operator/flinkapplications/wordcount-operator-example + selfLink: v1beta1 uid: a2855178-b29c-11e9-9a3b-025000000001 spec: entryClass: org.apache.flink.WordCount diff --git a/examples/wordcount/flink-operator-custom-resource.yaml b/examples/wordcount/flink-operator-custom-resource.yaml index cf55a383..ddc8314f 100644 --- a/examples/wordcount/flink-operator-custom-resource.yaml +++ b/examples/wordcount/flink-operator-custom-resource.yaml @@ -1,4 +1,4 @@ -apiVersion: flink.k8s.io/v1alpha1 +apiVersion: flink.k8s.io/v1beta1 kind: FlinkApplication metadata: name: wordcount-operator-example diff --git a/integ/checkpoint_failure_test.go b/integ/checkpoint_failure_test.go index d47f0845..7cc85537 100644 --- a/integ/checkpoint_failure_test.go +++ b/integ/checkpoint_failure_test.go @@ -6,7 +6,7 @@ import ( "os" "time" - "github.com/lyft/flinkk8soperator/pkg/apis/app/v1alpha1" + "github.com/lyft/flinkk8soperator/pkg/apis/app/v1beta1" "github.com/prometheus/common/log" . "gopkg.in/check.v1" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -27,7 +27,7 @@ func failingJobTest(s *IntegSuite, c *C, testName string, causeFailure func()) { // Cause it to fail causeFailure() - c.Assert(s.Util.WaitForPhase(config.Name, v1alpha1.FlinkApplicationRunning, v1alpha1.FlinkApplicationDeployFailed), IsNil) + c.Assert(s.Util.WaitForPhase(config.Name, v1beta1.FlinkApplicationRunning, v1beta1.FlinkApplicationDeployFailed), IsNil) // wait a bit for it to start failing time.Sleep(5 * time.Second) @@ -40,7 +40,7 @@ func failingJobTest(s *IntegSuite, c *C, testName string, causeFailure func()) { c.Assert(err, IsNil) // because the checkpoint will fail, the app should move to deploy failed - c.Assert(s.Util.WaitForPhase(config.Name, v1alpha1.FlinkApplicationDeployFailed), IsNil) + c.Assert(s.Util.WaitForPhase(config.Name, v1beta1.FlinkApplicationDeployFailed), IsNil) // And the job should not have been updated newApp, err := s.Util.GetFlinkApplication(config.Name) diff --git a/integ/simple_test.go b/integ/simple_test.go index 9cdae5fb..52b537cb 100644 --- a/integ/simple_test.go +++ b/integ/simple_test.go @@ -9,7 +9,7 @@ import ( "os" "time" - "github.com/lyft/flinkk8soperator/pkg/apis/app/v1alpha1" + "github.com/lyft/flinkk8soperator/pkg/apis/app/v1beta1" "github.com/lyft/flinkk8soperator/pkg/controller/flink/client" "github.com/prometheus/common/log" . "gopkg.in/check.v1" @@ -19,7 +19,7 @@ import ( const NewImage = "lyft/operator-test-app:b1b3cb8e8f98bd41f44f9c89f8462ce255e0d13f.2" -func updateAndValidate(c *C, s *IntegSuite, name string, updateFn func(app *v1alpha1.FlinkApplication), failurePhase v1alpha1.FlinkApplicationPhase) *v1alpha1.FlinkApplication { +func updateAndValidate(c *C, s *IntegSuite, name string, updateFn func(app *v1beta1.FlinkApplication), failurePhase v1beta1.FlinkApplicationPhase) *v1beta1.FlinkApplication { app, err := s.Util.GetFlinkApplication(name) c.Assert(err, IsNil) @@ -29,8 +29,8 @@ func updateAndValidate(c *C, s *IntegSuite, name string, updateFn func(app *v1al _, err = s.Util.FlinkApps().Update(app) c.Assert(err, IsNil) - c.Assert(s.Util.WaitForPhase(name, v1alpha1.FlinkApplicationSavepointing, failurePhase), IsNil) - c.Assert(s.Util.WaitForPhase(name, v1alpha1.FlinkApplicationRunning, failurePhase), IsNil) + c.Assert(s.Util.WaitForPhase(name, v1beta1.FlinkApplicationSavepointing, failurePhase), IsNil) + c.Assert(s.Util.WaitForPhase(name, v1beta1.FlinkApplicationRunning, failurePhase), IsNil) c.Assert(s.Util.WaitForAllTasksInState(name, "RUNNING"), IsNil) // check that it really updated @@ -80,7 +80,7 @@ func (s *IntegSuite) TestSimple(c *C) { c.Assert(s.Util.CreateFlinkApplication(config), IsNil, Commentf("Failed to create flink application")) - c.Assert(s.Util.WaitForPhase(config.Name, v1alpha1.FlinkApplicationRunning, v1alpha1.FlinkApplicationDeployFailed), IsNil) + c.Assert(s.Util.WaitForPhase(config.Name, v1beta1.FlinkApplicationRunning, v1beta1.FlinkApplicationDeployFailed), IsNil) c.Assert(s.Util.WaitForAllTasksInState(config.Name, "RUNNING"), IsNil) pods, err := s.Util.KubeClient.CoreV1().Pods(s.Util.Namespace.Name). @@ -94,9 +94,9 @@ func (s *IntegSuite) TestSimple(c *C) { log.Info("Application started successfully") // test updating the app with a new image - newApp := updateAndValidate(c, s, config.Name, func(app *v1alpha1.FlinkApplication) { + newApp := updateAndValidate(c, s, config.Name, func(app *v1beta1.FlinkApplication) { app.Spec.Image = NewImage - }, v1alpha1.FlinkApplicationDeployFailed) + }, v1beta1.FlinkApplicationDeployFailed) // check that the pods have the new image c.Assert(newApp.Spec.Image, Equals, NewImage) pods, err = s.Util.KubeClient.CoreV1().Pods(s.Util.Namespace.Name). @@ -108,9 +108,9 @@ func (s *IntegSuite) TestSimple(c *C) { } // test updating the app with a config change - newApp = updateAndValidate(c, s, config.Name, func(app *v1alpha1.FlinkApplication) { + newApp = updateAndValidate(c, s, config.Name, func(app *v1beta1.FlinkApplication) { app.Spec.FlinkConfig["akka.client.timeout"] = "23 s" - }, v1alpha1.FlinkApplicationDeployFailed) + }, v1beta1.FlinkApplicationDeployFailed) // validate the config has been applied res, err := s.Util.FlinkAPIGet(newApp, "/jobmanager/config") c.Assert(err, IsNil) @@ -137,9 +137,9 @@ func (s *IntegSuite) TestSimple(c *C) { _, err = s.Util.FlinkApps().Update(newApp) c.Assert(err, IsNil) - c.Assert(s.Util.WaitForPhase(newApp.Name, v1alpha1.FlinkApplicationSavepointing, ""), IsNil) + c.Assert(s.Util.WaitForPhase(newApp.Name, v1beta1.FlinkApplicationSavepointing, ""), IsNil) // we should end up in the DeployFailed phase - c.Assert(s.Util.WaitForPhase(newApp.Name, v1alpha1.FlinkApplicationDeployFailed, ""), IsNil) + c.Assert(s.Util.WaitForPhase(newApp.Name, v1beta1.FlinkApplicationDeployFailed, ""), IsNil) log.Info("Job is in deploy failed, waiting for tasks to start") @@ -166,7 +166,7 @@ func (s *IntegSuite) TestSimple(c *C) { log.Info("Attempting to roll forward") // and we should be able to roll forward by resubmitting with a fixed config - updateAndValidate(c, s, config.Name, func(app *v1alpha1.FlinkApplication) { + updateAndValidate(c, s, config.Name, func(app *v1beta1.FlinkApplication) { app.Spec.JarName = config.Spec.JarName app.Spec.RestartNonce = "rollback2" }, "") @@ -191,7 +191,7 @@ func (s *IntegSuite) TestSimple(c *C) { newApp.Spec.TaskManagerConfig.Resources = &TaskManagerDefaultResources _, _ = s.Util.FlinkApps().Update(newApp) - c.Assert(s.Util.WaitForPhase(newApp.Name, v1alpha1.FlinkApplicationClusterStarting, ""), IsNil) + c.Assert(s.Util.WaitForPhase(newApp.Name, v1beta1.FlinkApplicationClusterStarting, ""), IsNil) // User realizes error and cancels the deploy log.Infof("Cancelling deploy...") @@ -199,12 +199,12 @@ func (s *IntegSuite) TestSimple(c *C) { _, _ = s.Util.FlinkApps().Update(newApp) // we should end up in the DeployFailed phase - c.Assert(s.Util.WaitForPhase(newApp.Name, v1alpha1.FlinkApplicationDeployFailed, ""), IsNil) + c.Assert(s.Util.WaitForPhase(newApp.Name, v1beta1.FlinkApplicationDeployFailed, ""), IsNil) c.Assert(newApp.Spec.ForceRollback, Equals, true) log.Info("User cancelled deploy. Job is in deploy failed, waiting for tasks to start") // but the job should still be running - c.Assert(newApp.Status.JobStatus.State, Equals, v1alpha1.Running) + c.Assert(newApp.Status.JobStatus.State, Equals, v1beta1.Running) log.Info("Attempting to roll forward with fix") // Fixing update @@ -219,7 +219,7 @@ func (s *IntegSuite) TestSimple(c *C) { }, } // and we should be able to roll forward by resubmitting with a fixed config - updateAndValidate(c, s, config.Name, func(app *v1alpha1.FlinkApplication) { + updateAndValidate(c, s, config.Name, func(app *v1beta1.FlinkApplication) { app.Spec.TaskManagerConfig.Resources = &TaskManagerFixedResources app.Spec.ForceRollback = false }, "") @@ -229,7 +229,7 @@ func (s *IntegSuite) TestSimple(c *C) { c.Assert(s.Util.FlinkApps().Delete(config.Name, &v1.DeleteOptions{}), IsNil) // validate that a savepoint was taken and the job was cancelled - var app *v1alpha1.FlinkApplication + var app *v1beta1.FlinkApplication for { app, err = s.Util.GetFlinkApplication(config.Name) c.Assert(err, IsNil) @@ -297,7 +297,7 @@ func (s *IntegSuite) TestRecovery(c *C) { c.Log("Application Created") // wait for it to be running - c.Assert(s.Util.WaitForPhase(config.Name, v1alpha1.FlinkApplicationRunning, v1alpha1.FlinkApplicationDeployFailed), IsNil) + c.Assert(s.Util.WaitForPhase(config.Name, v1beta1.FlinkApplicationRunning, v1beta1.FlinkApplicationDeployFailed), IsNil) c.Assert(s.Util.WaitForAllTasksInState(config.Name, "RUNNING"), IsNil) c.Log("Application running") @@ -347,7 +347,7 @@ func (s *IntegSuite) TestRecovery(c *C) { } c.Assert(err, IsNil) - c.Assert(s.Util.WaitForPhase(config.Name, v1alpha1.FlinkApplicationRunning, v1alpha1.FlinkApplicationDeployFailed), IsNil) + c.Assert(s.Util.WaitForPhase(config.Name, v1beta1.FlinkApplicationRunning, v1beta1.FlinkApplicationDeployFailed), IsNil) // stop it from failing c.Assert(os.Remove(s.Util.CheckpointDir+"/fail"), IsNil) diff --git a/integ/test_app.yaml b/integ/test_app.yaml index c338c617..afe1d82b 100644 --- a/integ/test_app.yaml +++ b/integ/test_app.yaml @@ -1,4 +1,4 @@ -apiVersion: flink.k8s.io/v1alpha1 +apiVersion: flink.k8s.io/v1beta1 kind: FlinkApplication metadata: name: operator-test-app diff --git a/integ/utils/utils.go b/integ/utils/utils.go index efd130f9..a35a90e6 100644 --- a/integ/utils/utils.go +++ b/integ/utils/utils.go @@ -11,8 +11,8 @@ import ( "time" "github.com/go-resty/resty" - "github.com/lyft/flinkk8soperator/pkg/apis/app/v1alpha1" - v1alpha12 "github.com/lyft/flinkk8soperator/pkg/client/clientset/versioned/typed/app/v1alpha1" + flinkapp "github.com/lyft/flinkk8soperator/pkg/apis/app/v1beta1" + client "github.com/lyft/flinkk8soperator/pkg/client/clientset/versioned/typed/app/v1beta1" "github.com/prometheus/common/log" appsv1 "k8s.io/api/apps/v1" v1 "k8s.io/api/core/v1" @@ -327,13 +327,13 @@ func (f *TestUtil) TailOperatorLogs() error { return nil } -func (f *TestUtil) ReadFlinkApplication(path string) (*v1alpha1.FlinkApplication, error) { +func (f *TestUtil) ReadFlinkApplication(path string) (*flinkapp.FlinkApplication, error) { file, err := getFile(path) if err != nil { return nil, err } - app := v1alpha1.FlinkApplication{} + app := flinkapp.FlinkApplication{} err = yaml.NewYAMLOrJSONDecoder(file, 2048).Decode(&app) if err != nil { return nil, err @@ -344,20 +344,20 @@ func (f *TestUtil) ReadFlinkApplication(path string) (*v1alpha1.FlinkApplication return &app, nil } -func (f *TestUtil) FlinkApps() v1alpha12.FlinkApplicationInterface { - return f.FlinkApplicationClient.FlinkV1alpha1().FlinkApplications(f.Namespace.Name) +func (f *TestUtil) FlinkApps() client.FlinkApplicationInterface { + return f.FlinkApplicationClient.FlinkV1beta1().FlinkApplications(f.Namespace.Name) } -func (f *TestUtil) CreateFlinkApplication(application *v1alpha1.FlinkApplication) error { +func (f *TestUtil) CreateFlinkApplication(application *flinkapp.FlinkApplication) error { _, err := f.FlinkApps().Create(application) return err } -func (f *TestUtil) GetFlinkApplication(name string) (*v1alpha1.FlinkApplication, error) { +func (f *TestUtil) GetFlinkApplication(name string) (*flinkapp.FlinkApplication, error) { return f.FlinkApps().Get(name, metav1.GetOptions{}) } -func (f *TestUtil) WaitForPhase(name string, phase v1alpha1.FlinkApplicationPhase, failurePhases ...v1alpha1.FlinkApplicationPhase) error { +func (f *TestUtil) WaitForPhase(name string, phase flinkapp.FlinkApplicationPhase, failurePhases ...flinkapp.FlinkApplicationPhase) error { for { app, err := f.FlinkApps().Get(name, metav1.GetOptions{}) @@ -379,7 +379,7 @@ func (f *TestUtil) WaitForPhase(name string, phase v1alpha1.FlinkApplicationPhas } } -func (f *TestUtil) FlinkAPIGet(app *v1alpha1.FlinkApplication, endpoint string) (interface{}, error) { +func (f *TestUtil) FlinkAPIGet(app *flinkapp.FlinkApplication, endpoint string) (interface{}, error) { url := fmt.Sprintf("http://localhost:8001/api/v1/namespaces/%s/"+ "services/%s:8081/proxy/%s", f.Namespace.Name, app.Name, endpoint) diff --git a/pkg/apis/app/addtoscheme_v1alpha1.go b/pkg/apis/app/addtoscheme_v1beta1.go similarity index 60% rename from pkg/apis/app/addtoscheme_v1alpha1.go rename to pkg/apis/app/addtoscheme_v1beta1.go index efa5f0e9..28922b80 100644 --- a/pkg/apis/app/addtoscheme_v1alpha1.go +++ b/pkg/apis/app/addtoscheme_v1beta1.go @@ -5,10 +5,10 @@ package apis import ( - "github.com/lyft/flinkk8soperator/pkg/apis/app/v1alpha1" + "github.com/lyft/flinkk8soperator/pkg/apis/app/v1beta1" ) func init() { // Register the types with the Scheme so the components can map objects to GroupVersionKinds and back - AddToSchemes = append(AddToSchemes, v1alpha1.SchemeBuilder.AddToScheme) + AddToSchemes = append(AddToSchemes, v1beta1.SchemeBuilder.AddToScheme) } diff --git a/pkg/apis/app/v1beta1/doc.go b/pkg/apis/app/v1beta1/doc.go new file mode 100644 index 00000000..79d6f57a --- /dev/null +++ b/pkg/apis/app/v1beta1/doc.go @@ -0,0 +1,3 @@ +// +k8s:deepcopy-gen=package +// +groupName=flink.k8s.io +package v1beta1 diff --git a/pkg/apis/app/v1beta1/register.go b/pkg/apis/app/v1beta1/register.go new file mode 100644 index 00000000..5c38ca7b --- /dev/null +++ b/pkg/apis/app/v1beta1/register.go @@ -0,0 +1,42 @@ +package v1beta1 + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/runtime/schema" +) + +const ( + version = "v1beta1" + groupName = "flink.k8s.io" + + FlinkApplicationKind = "FlinkApplication" +) + +var ( + SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes) + AddToScheme = SchemeBuilder.AddToScheme + // SchemeGroupVersion is the group version used to register these objects. + SchemeGroupVersion = schema.GroupVersion{Group: groupName, Version: version} +) + +// GetKind takes an unqualified kind and returns back a Group qualified GroupKind +func Kind(kind string) schema.GroupKind { + return SchemeGroupVersion.WithKind(kind).GroupKind() +} + +// Resource takes an unqualified resource and returns a Group qualified GroupResource +func Resource(resource string) schema.GroupResource { + return SchemeGroupVersion.WithResource(resource).GroupResource() +} + +// addKnownTypes adds the set of types defined in this package to the supplied scheme. +func addKnownTypes(scheme *runtime.Scheme) error { + scheme.AddKnownTypes(SchemeGroupVersion, + &FlinkApplication{}, + &FlinkApplicationList{}, + ) + + metav1.AddToGroupVersion(scheme, SchemeGroupVersion) + return nil +} diff --git a/pkg/apis/app/v1beta1/types.go b/pkg/apis/app/v1beta1/types.go new file mode 100644 index 00000000..60b51be1 --- /dev/null +++ b/pkg/apis/app/v1beta1/types.go @@ -0,0 +1,267 @@ +package v1beta1 + +import ( + "fmt" + + "github.com/lyft/flinkk8soperator/pkg/controller/flink/client" + + apiv1 "k8s.io/api/core/v1" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +type FlinkApplicationList struct { + metav1.TypeMeta `json:",inline"` + metav1.ListMeta `json:"metadata"` + Items []FlinkApplication `json:"items"` +} + +// +genclient +// +genclient:noStatus +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object +// +k8s:defaulter-gen=true +type FlinkApplication struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata"` + Spec FlinkApplicationSpec `json:"spec"` + Status FlinkApplicationStatus `json:"status,omitempty"` +} + +type FlinkApplicationSpec struct { + Image string `json:"image,omitempty" protobuf:"bytes,2,opt,name=image"` + ImagePullPolicy apiv1.PullPolicy `json:"imagePullPolicy,omitempty" protobuf:"bytes,14,opt,name=imagePullPolicy,casttype=PullPolicy"` + ImagePullSecrets []apiv1.LocalObjectReference `json:"imagePullSecrets,omitempty" patchStrategy:"merge" patchMergeKey:"name" protobuf:"bytes,15,rep,name=imagePullSecrets"` + FlinkConfig FlinkConfig `json:"flinkConfig"` + FlinkVersion string `json:"flinkVersion"` + TaskManagerConfig TaskManagerConfig `json:"taskManagerConfig,omitempty"` + JobManagerConfig JobManagerConfig `json:"jobManagerConfig,omitempty"` + JarName string `json:"jarName"` + Parallelism int32 `json:"parallelism"` + EntryClass string `json:"entryClass,omitempty"` + ProgramArgs string `json:"programArgs,omitempty"` + SavepointInfo SavepointInfo `json:"savepointInfo,omitempty"` + DeploymentMode DeploymentMode `json:"deploymentMode,omitempty"` + RPCPort *int32 `json:"rpcPort,omitempty"` + BlobPort *int32 `json:"blobPort,omitempty"` + QueryPort *int32 `json:"queryPort,omitempty"` + UIPort *int32 `json:"uiPort,omitempty"` + MetricsQueryPort *int32 `json:"metricsQueryPort,omitempty"` + Volumes []apiv1.Volume `json:"volumes,omitempty"` + VolumeMounts []apiv1.VolumeMount `json:"volumeMounts,omitempty"` + RestartNonce string `json:"restartNonce"` + DeleteMode DeleteMode `json:"deleteMode,omitempty"` + AllowNonRestoredState bool `json:"allowNonRestoredState,omitempty"` + ForceRollback bool `json:"forceRollback"` +} + +type FlinkConfig map[string]interface{} + +// Workaround for https://github.com/kubernetes-sigs/kubebuilder/issues/528 +func (in *FlinkConfig) DeepCopyInto(out *FlinkConfig) { + if in == nil { + *out = nil + } else { + *out = make(map[string]interface{}, len(*in)) + for k, v := range *in { + (*out)[k] = deepCopyJSONValue(v) + } + } +} + +func deepCopyJSONValue(x interface{}) interface{} { + switch x := x.(type) { + case map[string]interface{}: + clone := make(map[string]interface{}, len(x)) + for k, v := range x { + clone[k] = deepCopyJSONValue(v) + } + return clone + case []interface{}: + clone := make([]interface{}, len(x)) + for i, v := range x { + clone[i] = deepCopyJSONValue(v) + } + return clone + case string, int, uint, int32, uint32, int64, uint64, bool, float32, float64, nil: + return x + default: + panic(fmt.Errorf("cannot deep copy %T", x)) + } +} + +func (in *FlinkConfig) DeepCopy() *FlinkConfig { + if in == nil { + return nil + } + out := new(FlinkConfig) + in.DeepCopyInto(out) + return out +} + +type JobManagerConfig struct { + Resources *apiv1.ResourceRequirements `json:"resources,omitempty"` + EnvConfig EnvironmentConfig `json:"envConfig"` + Replicas *int32 `json:"replicas,omitempty"` + OffHeapMemoryFraction *float64 `json:"offHeapMemoryFraction,omitempty"` + NodeSelector map[string]string `json:"nodeSelector,omitempty"` +} + +type TaskManagerConfig struct { + Resources *apiv1.ResourceRequirements `json:"resources,omitempty"` + EnvConfig EnvironmentConfig `json:"envConfig"` + TaskSlots *int32 `json:"taskSlots,omitempty"` + OffHeapMemoryFraction *float64 `json:"offHeapMemoryFraction,omitempty"` + NodeSelector map[string]string `json:"nodeSelector,omitempty"` +} + +type EnvironmentConfig struct { + EnvFrom []apiv1.EnvFromSource `json:"envFrom,omitempty"` + Env []apiv1.EnvVar `json:"env,omitempty"` +} + +type SavepointInfo struct { + SavepointLocation string `json:"savepointLocation,omitempty"` + TriggerID string `json:"triggerId,omitempty"` +} + +type FlinkClusterStatus struct { + Health HealthStatus `json:"health,omitempty"` + NumberOfTaskManagers int32 `json:"numberOfTaskManagers,omitempty"` + HealthyTaskManagers int32 `json:"healthyTaskManagers,omitepty"` + NumberOfTaskSlots int32 `json:"numberOfTaskSlots,omitempty"` + AvailableTaskSlots int32 `json:"availableTaskSlots"` +} + +type FlinkJobStatus struct { + JobID string `json:"jobID,omitEmpty"` + Health HealthStatus `json:"health,omitEmpty"` + State JobState `json:"state,omitEmpty"` + + JarName string `json:"jarName"` + Parallelism int32 `json:"parallelism"` + EntryClass string `json:"entryClass,omitempty"` + ProgramArgs string `json:"programArgs,omitempty"` + AllowNonRestoredState bool `json:"allowNonRestoredState,omitempty"` + + StartTime *metav1.Time `json:"startTime,omitEmpty"` + JobRestartCount int32 `json:"jobRestartCount,omitEmpty"` + CompletedCheckpointCount int32 `json:"completedCheckpointCount,omitEmpty"` + FailedCheckpointCount int32 `json:"failedCheckpointCount,omitEmpty"` + LastCheckpointTime *metav1.Time `json:"lastCheckpointTime,omitEmpty"` + RestorePath string `json:"restorePath,omitEmpty"` + RestoreTime *metav1.Time `json:"restoreTime,omitEmpty"` + LastFailingTime *metav1.Time `json:"lastFailingTime,omitEmpty"` +} + +type FlinkApplicationStatus struct { + Phase FlinkApplicationPhase `json:"phase"` + StartedAt *metav1.Time `json:"startedAt,omitempty"` + LastUpdatedAt *metav1.Time `json:"lastUpdatedAt,omitempty"` + Reason string `json:"reason,omitempty"` + ClusterStatus FlinkClusterStatus `json:"clusterStatus,omitempty"` + JobStatus FlinkJobStatus `json:"jobStatus"` + FailedDeployHash string `json:"failedDeployHash,omitEmpty"` + RollbackHash string `json:"rollbackHash,omitEmpty"` + DeployHash string `json:"deployHash"` + RetryCount int32 `json:"retryCount,omitEmpty"` + LastSeenError *client.FlinkApplicationError `json:"lastSeenError,omitEmpty"` +} + +func (in *FlinkApplicationStatus) GetPhase() FlinkApplicationPhase { + return in.Phase +} + +func (in *FlinkApplicationStatus) UpdatePhase(phase FlinkApplicationPhase, reason string) { + now := metav1.Now() + if in.StartedAt == nil { + in.StartedAt = &now + in.LastUpdatedAt = &now + } + in.Reason = reason + in.Phase = phase +} + +func (in *FlinkApplicationStatus) TouchResource(reason string) { + now := metav1.Now() + in.LastUpdatedAt = &now + in.Reason = reason +} + +type FlinkApplicationPhase string + +func (p FlinkApplicationPhase) VerboseString() string { + phaseName := string(p) + if p == FlinkApplicationNew { + phaseName = "New" + } + return phaseName +} + +// As you add more ApplicationPhase please add it to FlinkApplicationPhases list +const ( + FlinkApplicationNew FlinkApplicationPhase = "" + FlinkApplicationUpdating FlinkApplicationPhase = "Updating" + FlinkApplicationClusterStarting FlinkApplicationPhase = "ClusterStarting" + FlinkApplicationSubmittingJob FlinkApplicationPhase = "SubmittingJob" + FlinkApplicationRunning FlinkApplicationPhase = "Running" + FlinkApplicationSavepointing FlinkApplicationPhase = "Savepointing" + FlinkApplicationDeleting FlinkApplicationPhase = "Deleting" + FlinkApplicationRollingBackJob FlinkApplicationPhase = "RollingBackJob" + FlinkApplicationDeployFailed FlinkApplicationPhase = "DeployFailed" +) + +var FlinkApplicationPhases = []FlinkApplicationPhase{ + FlinkApplicationNew, + FlinkApplicationUpdating, + FlinkApplicationClusterStarting, + FlinkApplicationSubmittingJob, + FlinkApplicationRunning, + FlinkApplicationSavepointing, + FlinkApplicationDeleting, + FlinkApplicationDeployFailed, + FlinkApplicationRollingBackJob, +} + +func IsRunningPhase(phase FlinkApplicationPhase) bool { + return phase == FlinkApplicationRunning || phase == FlinkApplicationDeployFailed +} + +type DeploymentMode string + +const ( + DeploymentModeSingle DeploymentMode = "Single" + DeploymentModeDual DeploymentMode = "Dual" +) + +type DeleteMode string + +const ( + DeleteModeSavepoint DeleteMode = "Savepoint" + DeleteModeForceCancel DeleteMode = "ForceCancel" + DeleteModeNone DeleteMode = "None" +) + +type HealthStatus string + +const ( + Green HealthStatus = "Green" + Yellow HealthStatus = "Yellow" + Red HealthStatus = "Red" +) + +type JobState string + +const ( + Created JobState = "CREATED" + Running JobState = "RUNNING" + Failing JobState = "FAILING" + Failed JobState = "FAILED" + Cancelling JobState = "CANCELLING" + Canceled JobState = "CANCELED" + Finished JobState = "FINISHED" + Restarting JobState = "RESTARTING" + Suspended JobState = "SUSPENDED" + Reconciling JobState = "RECONCILING" +) diff --git a/pkg/apis/app/v1beta1/zz_generated.deepcopy.go b/pkg/apis/app/v1beta1/zz_generated.deepcopy.go new file mode 100644 index 00000000..bfa75045 --- /dev/null +++ b/pkg/apis/app/v1beta1/zz_generated.deepcopy.go @@ -0,0 +1,337 @@ +// +build !ignore_autogenerated + +// Code generated by deepcopy-gen. DO NOT EDIT. + +package v1beta1 + +import ( + v1 "k8s.io/api/core/v1" + runtime "k8s.io/apimachinery/pkg/runtime" +) + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *EnvironmentConfig) DeepCopyInto(out *EnvironmentConfig) { + *out = *in + if in.EnvFrom != nil { + in, out := &in.EnvFrom, &out.EnvFrom + *out = make([]v1.EnvFromSource, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + if in.Env != nil { + in, out := &in.Env, &out.Env + *out = make([]v1.EnvVar, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new EnvironmentConfig. +func (in *EnvironmentConfig) DeepCopy() *EnvironmentConfig { + if in == nil { + return nil + } + out := new(EnvironmentConfig) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *FlinkApplication) DeepCopyInto(out *FlinkApplication) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Spec.DeepCopyInto(&out.Spec) + in.Status.DeepCopyInto(&out.Status) + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new FlinkApplication. +func (in *FlinkApplication) DeepCopy() *FlinkApplication { + if in == nil { + return nil + } + out := new(FlinkApplication) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *FlinkApplication) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *FlinkApplicationList) DeepCopyInto(out *FlinkApplicationList) { + *out = *in + out.TypeMeta = in.TypeMeta + out.ListMeta = in.ListMeta + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]FlinkApplication, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new FlinkApplicationList. +func (in *FlinkApplicationList) DeepCopy() *FlinkApplicationList { + if in == nil { + return nil + } + out := new(FlinkApplicationList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *FlinkApplicationList) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *FlinkApplicationSpec) DeepCopyInto(out *FlinkApplicationSpec) { + *out = *in + if in.ImagePullSecrets != nil { + in, out := &in.ImagePullSecrets, &out.ImagePullSecrets + *out = make([]v1.LocalObjectReference, len(*in)) + copy(*out, *in) + } + in.FlinkConfig.DeepCopyInto(&out.FlinkConfig) + in.TaskManagerConfig.DeepCopyInto(&out.TaskManagerConfig) + in.JobManagerConfig.DeepCopyInto(&out.JobManagerConfig) + out.SavepointInfo = in.SavepointInfo + if in.RPCPort != nil { + in, out := &in.RPCPort, &out.RPCPort + *out = new(int32) + **out = **in + } + if in.BlobPort != nil { + in, out := &in.BlobPort, &out.BlobPort + *out = new(int32) + **out = **in + } + if in.QueryPort != nil { + in, out := &in.QueryPort, &out.QueryPort + *out = new(int32) + **out = **in + } + if in.UIPort != nil { + in, out := &in.UIPort, &out.UIPort + *out = new(int32) + **out = **in + } + if in.MetricsQueryPort != nil { + in, out := &in.MetricsQueryPort, &out.MetricsQueryPort + *out = new(int32) + **out = **in + } + if in.Volumes != nil { + in, out := &in.Volumes, &out.Volumes + *out = make([]v1.Volume, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + if in.VolumeMounts != nil { + in, out := &in.VolumeMounts, &out.VolumeMounts + *out = make([]v1.VolumeMount, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new FlinkApplicationSpec. +func (in *FlinkApplicationSpec) DeepCopy() *FlinkApplicationSpec { + if in == nil { + return nil + } + out := new(FlinkApplicationSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *FlinkApplicationStatus) DeepCopyInto(out *FlinkApplicationStatus) { + *out = *in + if in.StartedAt != nil { + in, out := &in.StartedAt, &out.StartedAt + *out = (*in).DeepCopy() + } + if in.LastUpdatedAt != nil { + in, out := &in.LastUpdatedAt, &out.LastUpdatedAt + *out = (*in).DeepCopy() + } + out.ClusterStatus = in.ClusterStatus + in.JobStatus.DeepCopyInto(&out.JobStatus) + if in.LastSeenError != nil { + in, out := &in.LastSeenError, &out.LastSeenError + *out = (*in).DeepCopy() + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new FlinkApplicationStatus. +func (in *FlinkApplicationStatus) DeepCopy() *FlinkApplicationStatus { + if in == nil { + return nil + } + out := new(FlinkApplicationStatus) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *FlinkClusterStatus) DeepCopyInto(out *FlinkClusterStatus) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new FlinkClusterStatus. +func (in *FlinkClusterStatus) DeepCopy() *FlinkClusterStatus { + if in == nil { + return nil + } + out := new(FlinkClusterStatus) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *FlinkJobStatus) DeepCopyInto(out *FlinkJobStatus) { + *out = *in + if in.StartTime != nil { + in, out := &in.StartTime, &out.StartTime + *out = (*in).DeepCopy() + } + if in.LastCheckpointTime != nil { + in, out := &in.LastCheckpointTime, &out.LastCheckpointTime + *out = (*in).DeepCopy() + } + if in.RestoreTime != nil { + in, out := &in.RestoreTime, &out.RestoreTime + *out = (*in).DeepCopy() + } + if in.LastFailingTime != nil { + in, out := &in.LastFailingTime, &out.LastFailingTime + *out = (*in).DeepCopy() + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new FlinkJobStatus. +func (in *FlinkJobStatus) DeepCopy() *FlinkJobStatus { + if in == nil { + return nil + } + out := new(FlinkJobStatus) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *JobManagerConfig) DeepCopyInto(out *JobManagerConfig) { + *out = *in + if in.Resources != nil { + in, out := &in.Resources, &out.Resources + *out = new(v1.ResourceRequirements) + (*in).DeepCopyInto(*out) + } + in.EnvConfig.DeepCopyInto(&out.EnvConfig) + if in.Replicas != nil { + in, out := &in.Replicas, &out.Replicas + *out = new(int32) + **out = **in + } + if in.OffHeapMemoryFraction != nil { + in, out := &in.OffHeapMemoryFraction, &out.OffHeapMemoryFraction + *out = new(float64) + **out = **in + } + if in.NodeSelector != nil { + in, out := &in.NodeSelector, &out.NodeSelector + *out = make(map[string]string, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new JobManagerConfig. +func (in *JobManagerConfig) DeepCopy() *JobManagerConfig { + if in == nil { + return nil + } + out := new(JobManagerConfig) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *SavepointInfo) DeepCopyInto(out *SavepointInfo) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SavepointInfo. +func (in *SavepointInfo) DeepCopy() *SavepointInfo { + if in == nil { + return nil + } + out := new(SavepointInfo) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *TaskManagerConfig) DeepCopyInto(out *TaskManagerConfig) { + *out = *in + if in.Resources != nil { + in, out := &in.Resources, &out.Resources + *out = new(v1.ResourceRequirements) + (*in).DeepCopyInto(*out) + } + in.EnvConfig.DeepCopyInto(&out.EnvConfig) + if in.TaskSlots != nil { + in, out := &in.TaskSlots, &out.TaskSlots + *out = new(int32) + **out = **in + } + if in.OffHeapMemoryFraction != nil { + in, out := &in.OffHeapMemoryFraction, &out.OffHeapMemoryFraction + *out = new(float64) + **out = **in + } + if in.NodeSelector != nil { + in, out := &in.NodeSelector, &out.NodeSelector + *out = make(map[string]string, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TaskManagerConfig. +func (in *TaskManagerConfig) DeepCopy() *TaskManagerConfig { + if in == nil { + return nil + } + out := new(TaskManagerConfig) + in.DeepCopyInto(out) + return out +} diff --git a/pkg/client/clientset/versioned/clientset.go b/pkg/client/clientset/versioned/clientset.go index 65968bdf..9aa48cc5 100644 --- a/pkg/client/clientset/versioned/clientset.go +++ b/pkg/client/clientset/versioned/clientset.go @@ -3,7 +3,7 @@ package versioned import ( - flinkv1alpha1 "github.com/lyft/flinkk8soperator/pkg/client/clientset/versioned/typed/app/v1alpha1" + flinkv1beta1 "github.com/lyft/flinkk8soperator/pkg/client/clientset/versioned/typed/app/v1beta1" discovery "k8s.io/client-go/discovery" rest "k8s.io/client-go/rest" flowcontrol "k8s.io/client-go/util/flowcontrol" @@ -11,19 +11,19 @@ import ( type Interface interface { Discovery() discovery.DiscoveryInterface - FlinkV1alpha1() flinkv1alpha1.FlinkV1alpha1Interface + FlinkV1beta1() flinkv1beta1.FlinkV1beta1Interface } // Clientset contains the clients for groups. Each group has exactly one // version included in a Clientset. type Clientset struct { *discovery.DiscoveryClient - flinkV1alpha1 *flinkv1alpha1.FlinkV1alpha1Client + flinkV1beta1 *flinkv1beta1.FlinkV1beta1Client } -// FlinkV1alpha1 retrieves the FlinkV1alpha1Client -func (c *Clientset) FlinkV1alpha1() flinkv1alpha1.FlinkV1alpha1Interface { - return c.flinkV1alpha1 +// FlinkV1beta1 retrieves the FlinkV1beta1Client +func (c *Clientset) FlinkV1beta1() flinkv1beta1.FlinkV1beta1Interface { + return c.flinkV1beta1 } // Discovery retrieves the DiscoveryClient @@ -42,7 +42,7 @@ func NewForConfig(c *rest.Config) (*Clientset, error) { } var cs Clientset var err error - cs.flinkV1alpha1, err = flinkv1alpha1.NewForConfig(&configShallowCopy) + cs.flinkV1beta1, err = flinkv1beta1.NewForConfig(&configShallowCopy) if err != nil { return nil, err } @@ -58,7 +58,7 @@ func NewForConfig(c *rest.Config) (*Clientset, error) { // panics if there is an error in the config. func NewForConfigOrDie(c *rest.Config) *Clientset { var cs Clientset - cs.flinkV1alpha1 = flinkv1alpha1.NewForConfigOrDie(c) + cs.flinkV1beta1 = flinkv1beta1.NewForConfigOrDie(c) cs.DiscoveryClient = discovery.NewDiscoveryClientForConfigOrDie(c) return &cs @@ -67,7 +67,7 @@ func NewForConfigOrDie(c *rest.Config) *Clientset { // New creates a new Clientset for the given RESTClient. func New(c rest.Interface) *Clientset { var cs Clientset - cs.flinkV1alpha1 = flinkv1alpha1.New(c) + cs.flinkV1beta1 = flinkv1beta1.New(c) cs.DiscoveryClient = discovery.NewDiscoveryClient(c) return &cs diff --git a/pkg/client/clientset/versioned/fake/clientset_generated.go b/pkg/client/clientset/versioned/fake/clientset_generated.go index 4fb6ff67..664662d9 100644 --- a/pkg/client/clientset/versioned/fake/clientset_generated.go +++ b/pkg/client/clientset/versioned/fake/clientset_generated.go @@ -4,8 +4,8 @@ package fake import ( clientset "github.com/lyft/flinkk8soperator/pkg/client/clientset/versioned" - flinkv1alpha1 "github.com/lyft/flinkk8soperator/pkg/client/clientset/versioned/typed/app/v1alpha1" - fakeflinkv1alpha1 "github.com/lyft/flinkk8soperator/pkg/client/clientset/versioned/typed/app/v1alpha1/fake" + flinkv1beta1 "github.com/lyft/flinkk8soperator/pkg/client/clientset/versioned/typed/app/v1beta1" + fakeflinkv1beta1 "github.com/lyft/flinkk8soperator/pkg/client/clientset/versioned/typed/app/v1beta1/fake" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/watch" "k8s.io/client-go/discovery" @@ -55,7 +55,7 @@ func (c *Clientset) Discovery() discovery.DiscoveryInterface { var _ clientset.Interface = &Clientset{} -// FlinkV1alpha1 retrieves the FlinkV1alpha1Client -func (c *Clientset) FlinkV1alpha1() flinkv1alpha1.FlinkV1alpha1Interface { - return &fakeflinkv1alpha1.FakeFlinkV1alpha1{Fake: &c.Fake} +// FlinkV1beta1 retrieves the FlinkV1beta1Client +func (c *Clientset) FlinkV1beta1() flinkv1beta1.FlinkV1beta1Interface { + return &fakeflinkv1beta1.FakeFlinkV1beta1{Fake: &c.Fake} } diff --git a/pkg/client/clientset/versioned/fake/register.go b/pkg/client/clientset/versioned/fake/register.go index 0f58e808..61bc01de 100644 --- a/pkg/client/clientset/versioned/fake/register.go +++ b/pkg/client/clientset/versioned/fake/register.go @@ -3,7 +3,7 @@ package fake import ( - flinkv1alpha1 "github.com/lyft/flinkk8soperator/pkg/apis/app/v1alpha1" + flinkv1beta1 "github.com/lyft/flinkk8soperator/pkg/apis/app/v1beta1" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" schema "k8s.io/apimachinery/pkg/runtime/schema" @@ -15,7 +15,7 @@ var scheme = runtime.NewScheme() var codecs = serializer.NewCodecFactory(scheme) var parameterCodec = runtime.NewParameterCodec(scheme) var localSchemeBuilder = runtime.SchemeBuilder{ - flinkv1alpha1.AddToScheme, + flinkv1beta1.AddToScheme, } // AddToScheme adds all types of this clientset into the given scheme. This allows composition diff --git a/pkg/client/clientset/versioned/scheme/register.go b/pkg/client/clientset/versioned/scheme/register.go index 5a935b10..8b472789 100644 --- a/pkg/client/clientset/versioned/scheme/register.go +++ b/pkg/client/clientset/versioned/scheme/register.go @@ -3,7 +3,7 @@ package scheme import ( - flinkv1alpha1 "github.com/lyft/flinkk8soperator/pkg/apis/app/v1alpha1" + flinkv1beta1 "github.com/lyft/flinkk8soperator/pkg/apis/app/v1beta1" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" schema "k8s.io/apimachinery/pkg/runtime/schema" @@ -15,7 +15,7 @@ var Scheme = runtime.NewScheme() var Codecs = serializer.NewCodecFactory(Scheme) var ParameterCodec = runtime.NewParameterCodec(Scheme) var localSchemeBuilder = runtime.SchemeBuilder{ - flinkv1alpha1.AddToScheme, + flinkv1beta1.AddToScheme, } // AddToScheme adds all types of this clientset into the given scheme. This allows composition diff --git a/pkg/client/clientset/versioned/typed/app/v1beta1/app_client.go b/pkg/client/clientset/versioned/typed/app/v1beta1/app_client.go new file mode 100644 index 00000000..0ad0754a --- /dev/null +++ b/pkg/client/clientset/versioned/typed/app/v1beta1/app_client.go @@ -0,0 +1,74 @@ +// Code generated by client-gen. DO NOT EDIT. + +package v1beta1 + +import ( + v1beta1 "github.com/lyft/flinkk8soperator/pkg/apis/app/v1beta1" + "github.com/lyft/flinkk8soperator/pkg/client/clientset/versioned/scheme" + serializer "k8s.io/apimachinery/pkg/runtime/serializer" + rest "k8s.io/client-go/rest" +) + +type FlinkV1beta1Interface interface { + RESTClient() rest.Interface + FlinkApplicationsGetter +} + +// FlinkV1beta1Client is used to interact with features provided by the flink.k8s.io group. +type FlinkV1beta1Client struct { + restClient rest.Interface +} + +func (c *FlinkV1beta1Client) FlinkApplications(namespace string) FlinkApplicationInterface { + return newFlinkApplications(c, namespace) +} + +// NewForConfig creates a new FlinkV1beta1Client for the given config. +func NewForConfig(c *rest.Config) (*FlinkV1beta1Client, error) { + config := *c + if err := setConfigDefaults(&config); err != nil { + return nil, err + } + client, err := rest.RESTClientFor(&config) + if err != nil { + return nil, err + } + return &FlinkV1beta1Client{client}, nil +} + +// NewForConfigOrDie creates a new FlinkV1beta1Client for the given config and +// panics if there is an error in the config. +func NewForConfigOrDie(c *rest.Config) *FlinkV1beta1Client { + client, err := NewForConfig(c) + if err != nil { + panic(err) + } + return client +} + +// New creates a new FlinkV1beta1Client for the given RESTClient. +func New(c rest.Interface) *FlinkV1beta1Client { + return &FlinkV1beta1Client{c} +} + +func setConfigDefaults(config *rest.Config) error { + gv := v1beta1.SchemeGroupVersion + config.GroupVersion = &gv + config.APIPath = "/apis" + config.NegotiatedSerializer = serializer.DirectCodecFactory{CodecFactory: scheme.Codecs} + + if config.UserAgent == "" { + config.UserAgent = rest.DefaultKubernetesUserAgent() + } + + return nil +} + +// RESTClient returns a RESTClient that is used to communicate +// with API server by this client implementation. +func (c *FlinkV1beta1Client) RESTClient() rest.Interface { + if c == nil { + return nil + } + return c.restClient +} diff --git a/pkg/client/clientset/versioned/typed/app/v1beta1/doc.go b/pkg/client/clientset/versioned/typed/app/v1beta1/doc.go new file mode 100644 index 00000000..897c0995 --- /dev/null +++ b/pkg/client/clientset/versioned/typed/app/v1beta1/doc.go @@ -0,0 +1,4 @@ +// Code generated by client-gen. DO NOT EDIT. + +// This package has the automatically generated typed clients. +package v1beta1 diff --git a/pkg/client/clientset/versioned/typed/app/v1beta1/fake/doc.go b/pkg/client/clientset/versioned/typed/app/v1beta1/fake/doc.go new file mode 100644 index 00000000..2b5ba4c8 --- /dev/null +++ b/pkg/client/clientset/versioned/typed/app/v1beta1/fake/doc.go @@ -0,0 +1,4 @@ +// Code generated by client-gen. DO NOT EDIT. + +// Package fake has the automatically generated clients. +package fake diff --git a/pkg/client/clientset/versioned/typed/app/v1beta1/fake/fake_app_client.go b/pkg/client/clientset/versioned/typed/app/v1beta1/fake/fake_app_client.go new file mode 100644 index 00000000..8f316743 --- /dev/null +++ b/pkg/client/clientset/versioned/typed/app/v1beta1/fake/fake_app_client.go @@ -0,0 +1,24 @@ +// Code generated by client-gen. DO NOT EDIT. + +package fake + +import ( + v1beta1 "github.com/lyft/flinkk8soperator/pkg/client/clientset/versioned/typed/app/v1beta1" + rest "k8s.io/client-go/rest" + testing "k8s.io/client-go/testing" +) + +type FakeFlinkV1beta1 struct { + *testing.Fake +} + +func (c *FakeFlinkV1beta1) FlinkApplications(namespace string) v1beta1.FlinkApplicationInterface { + return &FakeFlinkApplications{c, namespace} +} + +// RESTClient returns a RESTClient that is used to communicate +// with API server by this client implementation. +func (c *FakeFlinkV1beta1) RESTClient() rest.Interface { + var ret *rest.RESTClient + return ret +} diff --git a/pkg/client/clientset/versioned/typed/app/v1beta1/fake/fake_flinkapplication.go b/pkg/client/clientset/versioned/typed/app/v1beta1/fake/fake_flinkapplication.go new file mode 100644 index 00000000..ca76b697 --- /dev/null +++ b/pkg/client/clientset/versioned/typed/app/v1beta1/fake/fake_flinkapplication.go @@ -0,0 +1,112 @@ +// Code generated by client-gen. DO NOT EDIT. + +package fake + +import ( + v1beta1 "github.com/lyft/flinkk8soperator/pkg/apis/app/v1beta1" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + labels "k8s.io/apimachinery/pkg/labels" + schema "k8s.io/apimachinery/pkg/runtime/schema" + types "k8s.io/apimachinery/pkg/types" + watch "k8s.io/apimachinery/pkg/watch" + testing "k8s.io/client-go/testing" +) + +// FakeFlinkApplications implements FlinkApplicationInterface +type FakeFlinkApplications struct { + Fake *FakeFlinkV1beta1 + ns string +} + +var flinkapplicationsResource = schema.GroupVersionResource{Group: "flink.k8s.io", Version: "v1beta1", Resource: "flinkapplications"} + +var flinkapplicationsKind = schema.GroupVersionKind{Group: "flink.k8s.io", Version: "v1beta1", Kind: "FlinkApplication"} + +// Get takes name of the flinkApplication, and returns the corresponding flinkApplication object, and an error if there is any. +func (c *FakeFlinkApplications) Get(name string, options v1.GetOptions) (result *v1beta1.FlinkApplication, err error) { + obj, err := c.Fake. + Invokes(testing.NewGetAction(flinkapplicationsResource, c.ns, name), &v1beta1.FlinkApplication{}) + + if obj == nil { + return nil, err + } + return obj.(*v1beta1.FlinkApplication), err +} + +// List takes label and field selectors, and returns the list of FlinkApplications that match those selectors. +func (c *FakeFlinkApplications) List(opts v1.ListOptions) (result *v1beta1.FlinkApplicationList, err error) { + obj, err := c.Fake. + Invokes(testing.NewListAction(flinkapplicationsResource, flinkapplicationsKind, c.ns, opts), &v1beta1.FlinkApplicationList{}) + + if obj == nil { + return nil, err + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &v1beta1.FlinkApplicationList{ListMeta: obj.(*v1beta1.FlinkApplicationList).ListMeta} + for _, item := range obj.(*v1beta1.FlinkApplicationList).Items { + if label.Matches(labels.Set(item.Labels)) { + list.Items = append(list.Items, item) + } + } + return list, err +} + +// Watch returns a watch.Interface that watches the requested flinkApplications. +func (c *FakeFlinkApplications) Watch(opts v1.ListOptions) (watch.Interface, error) { + return c.Fake. + InvokesWatch(testing.NewWatchAction(flinkapplicationsResource, c.ns, opts)) + +} + +// Create takes the representation of a flinkApplication and creates it. Returns the server's representation of the flinkApplication, and an error, if there is any. +func (c *FakeFlinkApplications) Create(flinkApplication *v1beta1.FlinkApplication) (result *v1beta1.FlinkApplication, err error) { + obj, err := c.Fake. + Invokes(testing.NewCreateAction(flinkapplicationsResource, c.ns, flinkApplication), &v1beta1.FlinkApplication{}) + + if obj == nil { + return nil, err + } + return obj.(*v1beta1.FlinkApplication), err +} + +// Update takes the representation of a flinkApplication and updates it. Returns the server's representation of the flinkApplication, and an error, if there is any. +func (c *FakeFlinkApplications) Update(flinkApplication *v1beta1.FlinkApplication) (result *v1beta1.FlinkApplication, err error) { + obj, err := c.Fake. + Invokes(testing.NewUpdateAction(flinkapplicationsResource, c.ns, flinkApplication), &v1beta1.FlinkApplication{}) + + if obj == nil { + return nil, err + } + return obj.(*v1beta1.FlinkApplication), err +} + +// Delete takes name of the flinkApplication and deletes it. Returns an error if one occurs. +func (c *FakeFlinkApplications) Delete(name string, options *v1.DeleteOptions) error { + _, err := c.Fake. + Invokes(testing.NewDeleteAction(flinkapplicationsResource, c.ns, name), &v1beta1.FlinkApplication{}) + + return err +} + +// DeleteCollection deletes a collection of objects. +func (c *FakeFlinkApplications) DeleteCollection(options *v1.DeleteOptions, listOptions v1.ListOptions) error { + action := testing.NewDeleteCollectionAction(flinkapplicationsResource, c.ns, listOptions) + + _, err := c.Fake.Invokes(action, &v1beta1.FlinkApplicationList{}) + return err +} + +// Patch applies the patch and returns the patched flinkApplication. +func (c *FakeFlinkApplications) Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1beta1.FlinkApplication, err error) { + obj, err := c.Fake. + Invokes(testing.NewPatchSubresourceAction(flinkapplicationsResource, c.ns, name, pt, data, subresources...), &v1beta1.FlinkApplication{}) + + if obj == nil { + return nil, err + } + return obj.(*v1beta1.FlinkApplication), err +} diff --git a/pkg/client/clientset/versioned/typed/app/v1beta1/flinkapplication.go b/pkg/client/clientset/versioned/typed/app/v1beta1/flinkapplication.go new file mode 100644 index 00000000..1085cff1 --- /dev/null +++ b/pkg/client/clientset/versioned/typed/app/v1beta1/flinkapplication.go @@ -0,0 +1,158 @@ +// Code generated by client-gen. DO NOT EDIT. + +package v1beta1 + +import ( + "time" + + v1beta1 "github.com/lyft/flinkk8soperator/pkg/apis/app/v1beta1" + scheme "github.com/lyft/flinkk8soperator/pkg/client/clientset/versioned/scheme" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + types "k8s.io/apimachinery/pkg/types" + watch "k8s.io/apimachinery/pkg/watch" + rest "k8s.io/client-go/rest" +) + +// FlinkApplicationsGetter has a method to return a FlinkApplicationInterface. +// A group's client should implement this interface. +type FlinkApplicationsGetter interface { + FlinkApplications(namespace string) FlinkApplicationInterface +} + +// FlinkApplicationInterface has methods to work with FlinkApplication resources. +type FlinkApplicationInterface interface { + Create(*v1beta1.FlinkApplication) (*v1beta1.FlinkApplication, error) + Update(*v1beta1.FlinkApplication) (*v1beta1.FlinkApplication, error) + Delete(name string, options *v1.DeleteOptions) error + DeleteCollection(options *v1.DeleteOptions, listOptions v1.ListOptions) error + Get(name string, options v1.GetOptions) (*v1beta1.FlinkApplication, error) + List(opts v1.ListOptions) (*v1beta1.FlinkApplicationList, error) + Watch(opts v1.ListOptions) (watch.Interface, error) + Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1beta1.FlinkApplication, err error) + FlinkApplicationExpansion +} + +// flinkApplications implements FlinkApplicationInterface +type flinkApplications struct { + client rest.Interface + ns string +} + +// newFlinkApplications returns a FlinkApplications +func newFlinkApplications(c *FlinkV1beta1Client, namespace string) *flinkApplications { + return &flinkApplications{ + client: c.RESTClient(), + ns: namespace, + } +} + +// Get takes name of the flinkApplication, and returns the corresponding flinkApplication object, and an error if there is any. +func (c *flinkApplications) Get(name string, options v1.GetOptions) (result *v1beta1.FlinkApplication, err error) { + result = &v1beta1.FlinkApplication{} + err = c.client.Get(). + Namespace(c.ns). + Resource("flinkapplications"). + Name(name). + VersionedParams(&options, scheme.ParameterCodec). + Do(). + Into(result) + return +} + +// List takes label and field selectors, and returns the list of FlinkApplications that match those selectors. +func (c *flinkApplications) List(opts v1.ListOptions) (result *v1beta1.FlinkApplicationList, err error) { + var timeout time.Duration + if opts.TimeoutSeconds != nil { + timeout = time.Duration(*opts.TimeoutSeconds) * time.Second + } + result = &v1beta1.FlinkApplicationList{} + err = c.client.Get(). + Namespace(c.ns). + Resource("flinkapplications"). + VersionedParams(&opts, scheme.ParameterCodec). + Timeout(timeout). + Do(). + Into(result) + return +} + +// Watch returns a watch.Interface that watches the requested flinkApplications. +func (c *flinkApplications) Watch(opts v1.ListOptions) (watch.Interface, error) { + var timeout time.Duration + if opts.TimeoutSeconds != nil { + timeout = time.Duration(*opts.TimeoutSeconds) * time.Second + } + opts.Watch = true + return c.client.Get(). + Namespace(c.ns). + Resource("flinkapplications"). + VersionedParams(&opts, scheme.ParameterCodec). + Timeout(timeout). + Watch() +} + +// Create takes the representation of a flinkApplication and creates it. Returns the server's representation of the flinkApplication, and an error, if there is any. +func (c *flinkApplications) Create(flinkApplication *v1beta1.FlinkApplication) (result *v1beta1.FlinkApplication, err error) { + result = &v1beta1.FlinkApplication{} + err = c.client.Post(). + Namespace(c.ns). + Resource("flinkapplications"). + Body(flinkApplication). + Do(). + Into(result) + return +} + +// Update takes the representation of a flinkApplication and updates it. Returns the server's representation of the flinkApplication, and an error, if there is any. +func (c *flinkApplications) Update(flinkApplication *v1beta1.FlinkApplication) (result *v1beta1.FlinkApplication, err error) { + result = &v1beta1.FlinkApplication{} + err = c.client.Put(). + Namespace(c.ns). + Resource("flinkapplications"). + Name(flinkApplication.Name). + Body(flinkApplication). + Do(). + Into(result) + return +} + +// Delete takes name of the flinkApplication and deletes it. Returns an error if one occurs. +func (c *flinkApplications) Delete(name string, options *v1.DeleteOptions) error { + return c.client.Delete(). + Namespace(c.ns). + Resource("flinkapplications"). + Name(name). + Body(options). + Do(). + Error() +} + +// DeleteCollection deletes a collection of objects. +func (c *flinkApplications) DeleteCollection(options *v1.DeleteOptions, listOptions v1.ListOptions) error { + var timeout time.Duration + if listOptions.TimeoutSeconds != nil { + timeout = time.Duration(*listOptions.TimeoutSeconds) * time.Second + } + return c.client.Delete(). + Namespace(c.ns). + Resource("flinkapplications"). + VersionedParams(&listOptions, scheme.ParameterCodec). + Timeout(timeout). + Body(options). + Do(). + Error() +} + +// Patch applies the patch and returns the patched flinkApplication. +func (c *flinkApplications) Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1beta1.FlinkApplication, err error) { + result = &v1beta1.FlinkApplication{} + err = c.client.Patch(pt). + Namespace(c.ns). + Resource("flinkapplications"). + SubResource(subresources...). + Name(name). + Body(data). + Do(). + Into(result) + return +} diff --git a/pkg/client/clientset/versioned/typed/app/v1beta1/generated_expansion.go b/pkg/client/clientset/versioned/typed/app/v1beta1/generated_expansion.go new file mode 100644 index 00000000..eaf95aa7 --- /dev/null +++ b/pkg/client/clientset/versioned/typed/app/v1beta1/generated_expansion.go @@ -0,0 +1,5 @@ +// Code generated by client-gen. DO NOT EDIT. + +package v1beta1 + +type FlinkApplicationExpansion interface{} diff --git a/pkg/controller/flink/config.go b/pkg/controller/flink/config.go index ac3a6e4b..484cac84 100644 --- a/pkg/controller/flink/config.go +++ b/pkg/controller/flink/config.go @@ -3,7 +3,7 @@ package flink import ( "strings" - "github.com/lyft/flinkk8soperator/pkg/apis/app/v1alpha1" + "github.com/lyft/flinkk8soperator/pkg/apis/app/v1beta1" "gopkg.in/yaml.v2" ) @@ -33,35 +33,35 @@ func getValidFraction(x *float64, y float64) float64 { return y } -func getTaskmanagerSlots(app *v1alpha1.FlinkApplication) int32 { +func getTaskmanagerSlots(app *v1beta1.FlinkApplication) int32 { return firstNonNil(app.Spec.TaskManagerConfig.TaskSlots, TaskManagerDefaultSlots) } -func getJobmanagerReplicas(app *v1alpha1.FlinkApplication) int32 { +func getJobmanagerReplicas(app *v1beta1.FlinkApplication) int32 { return firstNonNil(app.Spec.JobManagerConfig.Replicas, JobManagerDefaultReplicaCount) } -func getRPCPort(app *v1alpha1.FlinkApplication) int32 { +func getRPCPort(app *v1beta1.FlinkApplication) int32 { return firstNonNil(app.Spec.RPCPort, RPCDefaultPort) } -func getUIPort(app *v1alpha1.FlinkApplication) int32 { +func getUIPort(app *v1beta1.FlinkApplication) int32 { return firstNonNil(app.Spec.UIPort, UIDefaultPort) } -func getQueryPort(app *v1alpha1.FlinkApplication) int32 { +func getQueryPort(app *v1beta1.FlinkApplication) int32 { return firstNonNil(app.Spec.QueryPort, QueryDefaultPort) } -func getBlobPort(app *v1alpha1.FlinkApplication) int32 { +func getBlobPort(app *v1beta1.FlinkApplication) int32 { return firstNonNil(app.Spec.BlobPort, BlobDefaultPort) } -func getInternalMetricsQueryPort(app *v1alpha1.FlinkApplication) int32 { +func getInternalMetricsQueryPort(app *v1beta1.FlinkApplication) int32 { return firstNonNil(app.Spec.MetricsQueryPort, MetricsQueryDefaultPort) } -func getTaskManagerMemory(application *v1alpha1.FlinkApplication) int64 { +func getTaskManagerMemory(application *v1beta1.FlinkApplication) int64 { tmResources := application.Spec.TaskManagerConfig.Resources if tmResources == nil { tmResources = &TaskManagerDefaultResources @@ -70,7 +70,7 @@ func getTaskManagerMemory(application *v1alpha1.FlinkApplication) int64 { return tmMemory } -func getJobManagerMemory(application *v1alpha1.FlinkApplication) int64 { +func getJobManagerMemory(application *v1beta1.FlinkApplication) int64 { jmResources := application.Spec.JobManagerConfig.Resources if jmResources == nil { jmResources = &JobManagerDefaultResources @@ -79,7 +79,7 @@ func getJobManagerMemory(application *v1alpha1.FlinkApplication) int64 { return jmMemory } -func getTaskManagerHeapMemory(app *v1alpha1.FlinkApplication) float64 { +func getTaskManagerHeapMemory(app *v1beta1.FlinkApplication) float64 { offHeapMemoryFrac := getValidFraction(app.Spec.TaskManagerConfig.OffHeapMemoryFraction, OffHeapMemoryDefaultFraction) tmMemory := float64(getTaskManagerMemory(app)) heapMemoryBytes := tmMemory - (tmMemory * offHeapMemoryFrac) @@ -87,7 +87,7 @@ func getTaskManagerHeapMemory(app *v1alpha1.FlinkApplication) float64 { return heapMemoryMB } -func getJobManagerHeapMemory(app *v1alpha1.FlinkApplication) float64 { +func getJobManagerHeapMemory(app *v1beta1.FlinkApplication) float64 { offHeapMemoryFrac := getValidFraction(app.Spec.JobManagerConfig.OffHeapMemoryFraction, OffHeapMemoryDefaultFraction) jmMemory := float64(getJobManagerMemory(app)) heapMemoryBytes := jmMemory - (jmMemory * offHeapMemoryFrac) @@ -97,10 +97,10 @@ func getJobManagerHeapMemory(app *v1alpha1.FlinkApplication) float64 { // Renders the flink configuration overrides stored in FlinkApplication.FlinkConfig into a // YAML string suitable for interpolating into flink-conf.yaml. -func renderFlinkConfig(app *v1alpha1.FlinkApplication) (string, error) { +func renderFlinkConfig(app *v1beta1.FlinkApplication) (string, error) { config := app.Spec.FlinkConfig.DeepCopy() if config == nil { - config = &v1alpha1.FlinkConfig{} + config = &v1beta1.FlinkConfig{} } // we will fill this in later using the versioned service @@ -122,7 +122,7 @@ func renderFlinkConfig(app *v1alpha1.FlinkApplication) (string, error) { return string(b), nil } -func isHAEnabled(flinkConfig v1alpha1.FlinkConfig) bool { +func isHAEnabled(flinkConfig v1beta1.FlinkConfig) bool { if val, ok := flinkConfig[HighAvailabilityKey]; ok { value := val.(string) if strings.ToLower(strings.TrimSpace(value)) != "none" { diff --git a/pkg/controller/flink/config_test.go b/pkg/controller/flink/config_test.go index d8e7774f..9b4eee91 100644 --- a/pkg/controller/flink/config_test.go +++ b/pkg/controller/flink/config_test.go @@ -6,7 +6,7 @@ import ( "strings" "testing" - "github.com/lyft/flinkk8soperator/pkg/apis/app/v1alpha1" + "github.com/lyft/flinkk8soperator/pkg/apis/app/v1beta1" "github.com/stretchr/testify/assert" coreV1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" @@ -18,28 +18,28 @@ func TestRenderFlinkConfigOverrides(t *testing.T) { blobPort := int32(1000) offHeapMemoryFrac := 0.5 - yaml, err := renderFlinkConfig(&v1alpha1.FlinkApplication{ + yaml, err := renderFlinkConfig(&v1beta1.FlinkApplication{ ObjectMeta: v1.ObjectMeta{ Name: "test-app", }, - Spec: v1alpha1.FlinkApplicationSpec{ + Spec: v1beta1.FlinkApplicationSpec{ FlinkConfig: map[string]interface{}{ "akka.timeout": "5s", "taskmanager.network.memory.fraction": 0.1, "taskmanager.network.request-backoff.max": 5000, "jobmanager.rpc.address": "wrong-address", }, - TaskManagerConfig: v1alpha1.TaskManagerConfig{ + TaskManagerConfig: v1beta1.TaskManagerConfig{ TaskSlots: &taskSlots, OffHeapMemoryFraction: &offHeapMemoryFrac, }, - JobManagerConfig: v1alpha1.JobManagerConfig{ + JobManagerConfig: v1beta1.JobManagerConfig{ OffHeapMemoryFraction: &offHeapMemoryFrac, }, BlobPort: &blobPort, }, - Status: v1alpha1.FlinkApplicationStatus{ - Phase: v1alpha1.FlinkApplicationNew, + Status: v1beta1.FlinkApplicationStatus{ + Phase: v1beta1.FlinkApplicationNew, }, }) @@ -68,22 +68,22 @@ func TestRenderFlinkConfigOverrides(t *testing.T) { } func TestGetTaskSlots(t *testing.T) { - app1 := v1alpha1.FlinkApplication{} + app1 := v1beta1.FlinkApplication{} assert.Equal(t, int32(TaskManagerDefaultSlots), getTaskmanagerSlots(&app1)) - app2 := v1alpha1.FlinkApplication{} + app2 := v1beta1.FlinkApplication{} taskSlots := int32(4) app2.Spec.TaskManagerConfig.TaskSlots = &taskSlots assert.Equal(t, int32(4), getTaskmanagerSlots(&app2)) } func TestGetJobManagerReplicas(t *testing.T) { - app1 := v1alpha1.FlinkApplication{} + app1 := v1beta1.FlinkApplication{} assert.Equal(t, int32(JobManagerDefaultReplicaCount), getJobmanagerReplicas(&app1)) } func TestGetJobManagerReplicasNonZero(t *testing.T) { - app1 := v1alpha1.FlinkApplication{} + app1 := v1beta1.FlinkApplication{} replicas := int32(4) app1.Spec.JobManagerConfig.Replicas = &replicas @@ -91,7 +91,7 @@ func TestGetJobManagerReplicasNonZero(t *testing.T) { } func TestGetTaskManagerMemory(t *testing.T) { - app := v1alpha1.FlinkApplication{} + app := v1beta1.FlinkApplication{} tmResources := coreV1.ResourceRequirements{ Requests: coreV1.ResourceList{ coreV1.ResourceCPU: resource.MustParse("2"), @@ -109,7 +109,7 @@ func TestGetTaskManagerMemory(t *testing.T) { } func TestGetJobManagerMemory(t *testing.T) { - app := v1alpha1.FlinkApplication{} + app := v1beta1.FlinkApplication{} tmResources := coreV1.ResourceRequirements{ Requests: coreV1.ResourceList{ coreV1.ResourceCPU: resource.MustParse("2"), @@ -127,7 +127,7 @@ func TestGetJobManagerMemory(t *testing.T) { } func TestGetTaskManagerHeapMemory(t *testing.T) { - app := v1alpha1.FlinkApplication{} + app := v1beta1.FlinkApplication{} tmResources := coreV1.ResourceRequirements{ Requests: coreV1.ResourceList{ coreV1.ResourceCPU: resource.MustParse("2"), @@ -148,7 +148,7 @@ func TestGetTaskManagerHeapMemory(t *testing.T) { } func TestGetJobManagerHeapMemory(t *testing.T) { - app := v1alpha1.FlinkApplication{} + app := v1beta1.FlinkApplication{} jmResources := coreV1.ResourceRequirements{ Requests: coreV1.ResourceList{ coreV1.ResourceCPU: resource.MustParse("2"), @@ -169,7 +169,7 @@ func TestGetJobManagerHeapMemory(t *testing.T) { } func TestInvalidMemoryFraction(t *testing.T) { - app := v1alpha1.FlinkApplication{} + app := v1beta1.FlinkApplication{} jmResources := coreV1.ResourceRequirements{ Requests: coreV1.ResourceList{ coreV1.ResourceCPU: resource.MustParse("2"), diff --git a/pkg/controller/flink/container_utils.go b/pkg/controller/flink/container_utils.go index 70cfd035..0e4305ed 100644 --- a/pkg/controller/flink/container_utils.go +++ b/pkg/controller/flink/container_utils.go @@ -6,7 +6,7 @@ import ( "github.com/benlaurie/objecthash/go/objecthash" - "github.com/lyft/flinkk8soperator/pkg/apis/app/v1alpha1" + "github.com/lyft/flinkk8soperator/pkg/apis/app/v1beta1" "github.com/lyft/flinkk8soperator/pkg/controller/common" "github.com/lyft/flinkk8soperator/pkg/controller/config" "github.com/lyft/flinkk8soperator/pkg/controller/k8" @@ -45,11 +45,11 @@ func getFlinkContainerName(containerName string) string { return containerName } -func getCommonAppLabels(app *v1alpha1.FlinkApplication) map[string]string { +func getCommonAppLabels(app *v1beta1.FlinkApplication) map[string]string { return k8.GetAppLabel(app.Name) } -func getCommonAnnotations(app *v1alpha1.FlinkApplication) map[string]string { +func getCommonAnnotations(app *v1beta1.FlinkApplication) map[string]string { annotations := common.DuplicateMap(app.Annotations) annotations[FlinkJobProperties] = fmt.Sprintf( "jarName: %s\nparallelism: %d\nentryClass:%s\nprogramArgs:\"%s\"", @@ -73,7 +73,7 @@ func GetAWSServiceEnv() []v1.EnvVar { } } -func getFlinkEnv(app *v1alpha1.FlinkApplication) ([]v1.EnvVar, error) { +func getFlinkEnv(app *v1beta1.FlinkApplication) ([]v1.EnvVar, error) { env := []v1.EnvVar{} appName := app.Name @@ -111,7 +111,7 @@ func getFlinkEnv(app *v1alpha1.FlinkApplication) ([]v1.EnvVar, error) { return env, nil } -func GetFlinkContainerEnv(app *v1alpha1.FlinkApplication) []v1.EnvVar { +func GetFlinkContainerEnv(app *v1beta1.FlinkApplication) []v1.EnvVar { env := []v1.EnvVar{} env = append(env, GetAWSServiceEnv()...) flinkEnv, err := getFlinkEnv(app) @@ -121,7 +121,7 @@ func GetFlinkContainerEnv(app *v1alpha1.FlinkApplication) []v1.EnvVar { return env } -func ImagePullPolicy(app *v1alpha1.FlinkApplication) v1.PullPolicy { +func ImagePullPolicy(app *v1beta1.FlinkApplication) v1.PullPolicy { if app.Spec.ImagePullPolicy == "" { return v1.PullIfNotPresent } @@ -157,7 +157,7 @@ func ComputeDeploymentHash(deployment appsv1.Deployment) ([]byte, error) { // Returns an 8 character hash sensitive to the application name, labels, annotations, and spec. // TODO: we may need to add collision-avoidance to this -func HashForApplication(app *v1alpha1.FlinkApplication) string { +func HashForApplication(app *v1beta1.FlinkApplication) string { // we round-trip through json to normalize the deployment objects jmDeployment := jobmanagerTemplate(app) jmDeployment.OwnerReferences = make([]metav1.OwnerReference, 0) @@ -192,7 +192,7 @@ func HashForApplication(app *v1alpha1.FlinkApplication) string { return fmt.Sprintf("%08x", hasher.Sum32()) } -func InjectOperatorCustomizedConfig(deployment *appsv1.Deployment, app *v1alpha1.FlinkApplication, hash string, deploymentType string) { +func InjectOperatorCustomizedConfig(deployment *appsv1.Deployment, app *v1beta1.FlinkApplication, hash string, deploymentType string) { var newContainers []v1.Container for _, container := range deployment.Spec.Template.Spec.Containers { var newEnv []v1.EnvVar diff --git a/pkg/controller/flink/container_utils_test.go b/pkg/controller/flink/container_utils_test.go index 946efcd3..008ca1bb 100644 --- a/pkg/controller/flink/container_utils_test.go +++ b/pkg/controller/flink/container_utils_test.go @@ -3,14 +3,14 @@ package flink import ( "testing" - "github.com/lyft/flinkk8soperator/pkg/apis/app/v1alpha1" + "github.com/lyft/flinkk8soperator/pkg/apis/app/v1beta1" "github.com/stretchr/testify/assert" v1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" ) func TestHashForApplication(t *testing.T) { - app := v1alpha1.FlinkApplication{} + app := v1beta1.FlinkApplication{} taskSlots := int32(8) app.Spec.TaskManagerConfig.TaskSlots = &taskSlots app.Spec.Parallelism = 4 @@ -49,7 +49,7 @@ func TestHashForApplication(t *testing.T) { } func TestHashForDifferentResourceScales(t *testing.T) { - app1 := v1alpha1.FlinkApplication{} + app1 := v1beta1.FlinkApplication{} app1.Spec.TaskManagerConfig.Resources = &v1.ResourceRequirements{ Requests: v1.ResourceList{ v1.ResourceCPU: resource.MustParse("0.5"), @@ -61,7 +61,7 @@ func TestHashForDifferentResourceScales(t *testing.T) { }, } - app2 := v1alpha1.FlinkApplication{} + app2 := v1beta1.FlinkApplication{} app2.Spec.TaskManagerConfig.Resources = &v1.ResourceRequirements{ Requests: v1.ResourceList{ v1.ResourceCPU: resource.MustParse("500m"), diff --git a/pkg/controller/flink/flink.go b/pkg/controller/flink/flink.go index f9c50638..fe3e4a9b 100644 --- a/pkg/controller/flink/flink.go +++ b/pkg/controller/flink/flink.go @@ -14,7 +14,7 @@ import ( controllerConfig "github.com/lyft/flinkk8soperator/pkg/controller/config" "github.com/lyft/flytestdlib/logger" - "github.com/lyft/flinkk8soperator/pkg/apis/app/v1alpha1" + "github.com/lyft/flinkk8soperator/pkg/apis/app/v1beta1" "github.com/lyft/flinkk8soperator/pkg/controller/flink/client" "github.com/lyft/flinkk8soperator/pkg/controller/k8" "github.com/lyft/flytestdlib/promutils" @@ -45,52 +45,52 @@ const failingIntervalThreshold = 1 * time.Minute // Interface to manage Flink Application in Kubernetes type ControllerInterface interface { // Creates a Flink cluster with necessary Job Manager, Task Managers and services for UI - CreateCluster(ctx context.Context, application *v1alpha1.FlinkApplication) error + CreateCluster(ctx context.Context, application *v1beta1.FlinkApplication) error // Cancels the running/active jobs in the Cluster for the Application after savepoint is created - CancelWithSavepoint(ctx context.Context, application *v1alpha1.FlinkApplication, hash string) (string, error) + CancelWithSavepoint(ctx context.Context, application *v1beta1.FlinkApplication, hash string) (string, error) // Force cancels the running/active job without taking a savepoint - ForceCancel(ctx context.Context, application *v1alpha1.FlinkApplication, hash string) error + ForceCancel(ctx context.Context, application *v1beta1.FlinkApplication, hash string) error // Starts the Job in the Flink Cluster - StartFlinkJob(ctx context.Context, application *v1alpha1.FlinkApplication, hash string, + StartFlinkJob(ctx context.Context, application *v1beta1.FlinkApplication, hash string, jarName string, parallelism int32, entryClass string, programArgs string, allowNonRestoredState bool) (string, error) // Savepoint creation is asynchronous. // Polls the status of the Savepoint, using the triggerID - GetSavepointStatus(ctx context.Context, application *v1alpha1.FlinkApplication, hash string) (*client.SavepointResponse, error) + GetSavepointStatus(ctx context.Context, application *v1beta1.FlinkApplication, hash string) (*client.SavepointResponse, error) // Check if the Flink Kubernetes Cluster is Ready. // Checks if all the pods of task and job managers are ready. - IsClusterReady(ctx context.Context, application *v1alpha1.FlinkApplication) (bool, error) + IsClusterReady(ctx context.Context, application *v1beta1.FlinkApplication) (bool, error) // Checks to see if the Flink Cluster is ready to handle API requests - IsServiceReady(ctx context.Context, application *v1alpha1.FlinkApplication, hash string) (bool, error) + IsServiceReady(ctx context.Context, application *v1beta1.FlinkApplication, hash string) (bool, error) // Returns the list of Jobs running on the Flink Cluster for the Application - GetJobsForApplication(ctx context.Context, application *v1alpha1.FlinkApplication, hash string) ([]client.FlinkJob, error) + GetJobsForApplication(ctx context.Context, application *v1beta1.FlinkApplication, hash string) ([]client.FlinkJob, error) // Returns the pair of deployments (tm/jm) for the current version of the application - GetCurrentDeploymentsForApp(ctx context.Context, application *v1alpha1.FlinkApplication) (*common.FlinkDeployment, error) + GetCurrentDeploymentsForApp(ctx context.Context, application *v1beta1.FlinkApplication) (*common.FlinkDeployment, error) // Deletes all old resources (deployments and services) for the app - DeleteOldResourcesForApp(ctx context.Context, app *v1alpha1.FlinkApplication) error + DeleteOldResourcesForApp(ctx context.Context, app *v1beta1.FlinkApplication) error // Attempts to find an externalized checkpoint for the job. This can be used to recover an application that is not // able to savepoint for some reason. - FindExternalizedCheckpoint(ctx context.Context, application *v1alpha1.FlinkApplication, hash string) (string, error) + FindExternalizedCheckpoint(ctx context.Context, application *v1beta1.FlinkApplication, hash string) (string, error) // Logs an event to the FlinkApplication resource and to the operator log - LogEvent(ctx context.Context, app *v1alpha1.FlinkApplication, eventType string, reason string, message string) + LogEvent(ctx context.Context, app *v1beta1.FlinkApplication, eventType string, reason string, message string) // Compares and updates new cluster status with current cluster status // Returns true if there is a change in ClusterStatus - CompareAndUpdateClusterStatus(ctx context.Context, application *v1alpha1.FlinkApplication, hash string) (bool, error) + CompareAndUpdateClusterStatus(ctx context.Context, application *v1beta1.FlinkApplication, hash string) (bool, error) // Compares and updates new job status with current job status // Returns true if there is a change in JobStatus - CompareAndUpdateJobStatus(ctx context.Context, app *v1alpha1.FlinkApplication, hash string) (bool, error) + CompareAndUpdateJobStatus(ctx context.Context, app *v1beta1.FlinkApplication, hash string) (bool, error) } func NewController(k8sCluster k8.ClusterInterface, eventRecorder record.EventRecorder, config controllerConfig.RuntimeConfig) ControllerInterface { @@ -131,7 +131,7 @@ type Controller struct { eventRecorder record.EventRecorder } -func getURLFromApp(application *v1alpha1.FlinkApplication, hash string) string { +func getURLFromApp(application *v1beta1.FlinkApplication, hash string) string { service := VersionedJobManagerServiceName(application, hash) cfg := controllerConfig.GetConfig() if cfg.UseProxy { @@ -155,7 +155,7 @@ func GetActiveFlinkJob(jobs []client.FlinkJob) *client.FlinkJob { } // returns true iff the deployment exactly matches the flink application -func (f *Controller) deploymentMatches(ctx context.Context, deployment *v1.Deployment, application *v1alpha1.FlinkApplication) bool { +func (f *Controller) deploymentMatches(ctx context.Context, deployment *v1.Deployment, application *v1beta1.FlinkApplication) bool { if DeploymentIsTaskmanager(deployment) { return TaskManagerDeploymentMatches(deployment, application) } @@ -167,7 +167,7 @@ func (f *Controller) deploymentMatches(ctx context.Context, deployment *v1.Deplo return false } -func (f *Controller) GetJobsForApplication(ctx context.Context, application *v1alpha1.FlinkApplication, hash string) ([]client.FlinkJob, error) { +func (f *Controller) GetJobsForApplication(ctx context.Context, application *v1beta1.FlinkApplication, hash string) ([]client.FlinkJob, error) { jobResponse, err := f.flinkClient.GetJobs(ctx, getURLFromApp(application, hash)) if err != nil { return nil, err @@ -178,7 +178,7 @@ func (f *Controller) GetJobsForApplication(ctx context.Context, application *v1a // The operator for now assumes and is intended to run single application per Flink Cluster. // Once we move to run multiple applications, this has to be removed/updated -func (f *Controller) getJobIDForApplication(application *v1alpha1.FlinkApplication) (string, error) { +func (f *Controller) getJobIDForApplication(application *v1beta1.FlinkApplication) (string, error) { if application.Status.JobStatus.JobID != "" { return application.Status.JobStatus.JobID, nil } @@ -186,7 +186,7 @@ func (f *Controller) getJobIDForApplication(application *v1alpha1.FlinkApplicati return "", errors.New("active job id not available") } -func (f *Controller) CancelWithSavepoint(ctx context.Context, application *v1alpha1.FlinkApplication, hash string) (string, error) { +func (f *Controller) CancelWithSavepoint(ctx context.Context, application *v1beta1.FlinkApplication, hash string) (string, error) { jobID, err := f.getJobIDForApplication(application) if err != nil { return "", err @@ -194,7 +194,7 @@ func (f *Controller) CancelWithSavepoint(ctx context.Context, application *v1alp return f.flinkClient.CancelJobWithSavepoint(ctx, getURLFromApp(application, hash), jobID) } -func (f *Controller) ForceCancel(ctx context.Context, application *v1alpha1.FlinkApplication, hash string) error { +func (f *Controller) ForceCancel(ctx context.Context, application *v1beta1.FlinkApplication, hash string) error { jobID, err := f.getJobIDForApplication(application) if err != nil { return err @@ -202,7 +202,7 @@ func (f *Controller) ForceCancel(ctx context.Context, application *v1alpha1.Flin return f.flinkClient.ForceCancelJob(ctx, getURLFromApp(application, hash), jobID) } -func (f *Controller) CreateCluster(ctx context.Context, application *v1alpha1.FlinkApplication) error { +func (f *Controller) CreateCluster(ctx context.Context, application *v1beta1.FlinkApplication) error { newlyCreatedJm, err := f.jobManager.CreateIfNotExist(ctx, application) if err != nil { logger.Errorf(ctx, "Job manager cluster creation did not succeed %v", err) @@ -228,7 +228,7 @@ func (f *Controller) CreateCluster(ctx context.Context, application *v1alpha1.Fl return nil } -func (f *Controller) StartFlinkJob(ctx context.Context, application *v1alpha1.FlinkApplication, hash string, +func (f *Controller) StartFlinkJob(ctx context.Context, application *v1beta1.FlinkApplication, hash string, jarName string, parallelism int32, entryClass string, programArgs string, allowNonRestoredState bool) (string, error) { response, err := f.flinkClient.SubmitJob( ctx, @@ -251,7 +251,7 @@ func (f *Controller) StartFlinkJob(ctx context.Context, application *v1alpha1.Fl return response.JobID, nil } -func (f *Controller) GetSavepointStatus(ctx context.Context, application *v1alpha1.FlinkApplication, hash string) (*client.SavepointResponse, error) { +func (f *Controller) GetSavepointStatus(ctx context.Context, application *v1beta1.FlinkApplication, hash string) (*client.SavepointResponse, error) { jobID, err := f.getJobIDForApplication(application) if err != nil { return nil, err @@ -259,7 +259,7 @@ func (f *Controller) GetSavepointStatus(ctx context.Context, application *v1alph return f.flinkClient.CheckSavepointStatus(ctx, getURLFromApp(application, hash), jobID, application.Spec.SavepointInfo.TriggerID) } -func (f *Controller) IsClusterReady(ctx context.Context, application *v1alpha1.FlinkApplication) (bool, error) { +func (f *Controller) IsClusterReady(ctx context.Context, application *v1beta1.FlinkApplication) (bool, error) { deployments, err := f.GetCurrentDeploymentsForApp(ctx, application) if deployments == nil || err != nil { return false, err @@ -277,7 +277,7 @@ func (f *Controller) IsClusterReady(ctx context.Context, application *v1alpha1.F return true, nil } -func (f *Controller) IsServiceReady(ctx context.Context, application *v1alpha1.FlinkApplication, hash string) (bool, error) { +func (f *Controller) IsServiceReady(ctx context.Context, application *v1beta1.FlinkApplication, hash string) (bool, error) { _, err := f.flinkClient.GetClusterOverview(ctx, getURLFromApp(application, hash)) if err != nil { logger.Infof(ctx, "Error response indicating flink API is not ready to handle request %v", err) @@ -311,7 +311,7 @@ func listToFlinkDeployment(ds []v1.Deployment, hash string) *common.FlinkDeploym return &fd } -func getCurrentHash(app *v1alpha1.FlinkApplication) string { +func getCurrentHash(app *v1beta1.FlinkApplication) string { appHash := HashForApplication(app) if appHash == app.Status.FailedDeployHash { @@ -323,7 +323,7 @@ func getCurrentHash(app *v1alpha1.FlinkApplication) string { // Gets the current deployment and any other deployments for the application. The current deployment will be the one // that matches the FlinkApplication, unless the FailedDeployHash is set, in which case it will be the one with that // hash. -func (f *Controller) GetCurrentDeploymentsForApp(ctx context.Context, application *v1alpha1.FlinkApplication) (*common.FlinkDeployment, error) { +func (f *Controller) GetCurrentDeploymentsForApp(ctx context.Context, application *v1beta1.FlinkApplication) (*common.FlinkDeployment, error) { labels := k8.GetAppLabel(application.Name) curHash := getCurrentHash(application) labels[FlinkAppHash] = curHash @@ -344,7 +344,7 @@ func (f *Controller) GetCurrentDeploymentsForApp(ctx context.Context, applicatio return cur, nil } -func (f *Controller) DeleteOldResourcesForApp(ctx context.Context, app *v1alpha1.FlinkApplication) error { +func (f *Controller) DeleteOldResourcesForApp(ctx context.Context, app *v1beta1.FlinkApplication) error { curHash := getCurrentHash(app) appLabel := k8.GetAppLabel(app.Name) @@ -398,7 +398,7 @@ func (f *Controller) DeleteOldResourcesForApp(ctx context.Context, app *v1alpha1 return nil } -func (f *Controller) FindExternalizedCheckpoint(ctx context.Context, application *v1alpha1.FlinkApplication, hash string) (string, error) { +func (f *Controller) FindExternalizedCheckpoint(ctx context.Context, application *v1beta1.FlinkApplication, hash string) (string, error) { checkpoint, err := f.flinkClient.GetLatestCheckpoint(ctx, getURLFromApp(application, hash), application.Status.JobStatus.JobID) if err != nil { return "", err @@ -415,17 +415,17 @@ func (f *Controller) FindExternalizedCheckpoint(ctx context.Context, application return checkpoint.ExternalPath, nil } -func (f *Controller) LogEvent(ctx context.Context, app *v1alpha1.FlinkApplication, eventType string, reason string, message string) { +func (f *Controller) LogEvent(ctx context.Context, app *v1beta1.FlinkApplication, eventType string, reason string, message string) { f.eventRecorder.Event(app, eventType, reason, message) logger.Infof(ctx, "Logged %s event: %s: %s", eventType, reason, message) } // Gets and updates the cluster status -func (f *Controller) CompareAndUpdateClusterStatus(ctx context.Context, application *v1alpha1.FlinkApplication, hash string) (bool, error) { +func (f *Controller) CompareAndUpdateClusterStatus(ctx context.Context, application *v1beta1.FlinkApplication, hash string) (bool, error) { // Error retrieving cluster / taskmanagers overview (after startup/readiness) --> Red // If there is an error this loop will return with Health set to Red oldClusterStatus := application.Status.ClusterStatus - application.Status.ClusterStatus.Health = v1alpha1.Red + application.Status.ClusterStatus.Health = v1beta1.Red deployment, err := f.GetCurrentDeploymentsForApp(ctx, application) if deployment == nil || err != nil { @@ -453,9 +453,9 @@ func (f *Controller) CompareAndUpdateClusterStatus(ctx context.Context, applicat // Healthy TaskManagers == Number of taskmanagers --> Green // Else --> Yellow if application.Status.ClusterStatus.HealthyTaskManagers == deployment.Taskmanager.Status.Replicas { - application.Status.ClusterStatus.Health = v1alpha1.Green + application.Status.ClusterStatus.Health = v1beta1.Green } else { - application.Status.ClusterStatus.Health = v1alpha1.Yellow + application.Status.ClusterStatus.Health = v1beta1.Yellow } return !apiequality.Semantic.DeepEqual(oldClusterStatus, application.Status.ClusterStatus), nil @@ -474,7 +474,7 @@ func getHealthyTaskManagerCount(response *client.TaskManagersResponse) int32 { } -func (f *Controller) CompareAndUpdateJobStatus(ctx context.Context, app *v1alpha1.FlinkApplication, hash string) (bool, error) { +func (f *Controller) CompareAndUpdateJobStatus(ctx context.Context, app *v1beta1.FlinkApplication, hash string) (bool, error) { // Initialize the last failing time to beginning of time if it's never been set if app.Status.JobStatus.LastFailingTime == nil { initTime := metav1.NewTime(time.Time{}) @@ -494,7 +494,7 @@ func (f *Controller) CompareAndUpdateJobStatus(ctx context.Context, app *v1alpha } // Job status - app.Status.JobStatus.State = v1alpha1.JobState(jobResponse.State) + app.Status.JobStatus.State = v1beta1.JobState(jobResponse.State) jobStartTime := metav1.NewTime(time.Unix(jobResponse.StartTime/1000, 0)) app.Status.JobStatus.StartTime = &jobStartTime @@ -523,16 +523,16 @@ func (f *Controller) CompareAndUpdateJobStatus(ctx context.Context, app *v1alpha // Time since last successful checkpoint > maxCheckpointTime --> YELLOW // Else --> Green - if app.Status.JobStatus.State == v1alpha1.Failing || time.Since(app.Status.JobStatus.LastFailingTime.Time) < + if app.Status.JobStatus.State == v1beta1.Failing || time.Since(app.Status.JobStatus.LastFailingTime.Time) < failingIntervalThreshold { - app.Status.JobStatus.Health = v1alpha1.Red + app.Status.JobStatus.Health = v1beta1.Red } else if time.Since(time.Unix(int64(lastCheckpointAgeSeconds), 0)) < maxCheckpointTime { - app.Status.JobStatus.Health = v1alpha1.Yellow + app.Status.JobStatus.Health = v1beta1.Yellow } else { - app.Status.JobStatus.Health = v1alpha1.Green + app.Status.JobStatus.Health = v1beta1.Green } // Update LastFailingTime - if app.Status.JobStatus.State == v1alpha1.Failing { + if app.Status.JobStatus.State == v1beta1.Failing { currTime := metav1.Now() app.Status.JobStatus.LastFailingTime = &currTime } diff --git a/pkg/controller/flink/flink_test.go b/pkg/controller/flink/flink_test.go index 95bb9c4b..0799fb94 100644 --- a/pkg/controller/flink/flink_test.go +++ b/pkg/controller/flink/flink_test.go @@ -9,7 +9,7 @@ import ( "time" - "github.com/lyft/flinkk8soperator/pkg/apis/app/v1alpha1" + "github.com/lyft/flinkk8soperator/pkg/apis/app/v1beta1" "github.com/lyft/flinkk8soperator/pkg/controller/common" "github.com/lyft/flinkk8soperator/pkg/controller/flink/client" clientMock "github.com/lyft/flinkk8soperator/pkg/controller/flink/client/mock" @@ -51,11 +51,11 @@ func getTestFlinkController() Controller { } } -func getFlinkTestApp() v1alpha1.FlinkApplication { - app := v1alpha1.FlinkApplication{ +func getFlinkTestApp() v1beta1.FlinkApplication { + app := v1beta1.FlinkApplication{ TypeMeta: metaV1.TypeMeta{ - Kind: v1alpha1.FlinkApplicationKind, - APIVersion: v1alpha1.SchemeGroupVersion.String(), + Kind: v1beta1.FlinkApplicationKind, + APIVersion: v1beta1.SchemeGroupVersion.String(), }, } app.Spec.Parallelism = 8 @@ -145,7 +145,7 @@ func TestFlinkApplicationChanged(t *testing.T) { assert.Nil(t, err) } -func testJobPropTriggersChange(t *testing.T, changeFun func(application *v1alpha1.FlinkApplication)) { +func testJobPropTriggersChange(t *testing.T, changeFun func(application *v1beta1.FlinkApplication)) { flinkControllerForTest := getTestFlinkController() flinkApp := getFlinkTestApp() @@ -180,19 +180,19 @@ func testJobPropTriggersChange(t *testing.T, changeFun func(application *v1alpha } func TestFlinkApplicationChangedJobProps(t *testing.T) { - testJobPropTriggersChange(t, func(app *v1alpha1.FlinkApplication) { + testJobPropTriggersChange(t, func(app *v1beta1.FlinkApplication) { app.Spec.Parallelism = 3 }) - testJobPropTriggersChange(t, func(app *v1alpha1.FlinkApplication) { + testJobPropTriggersChange(t, func(app *v1beta1.FlinkApplication) { app.Spec.JarName = "another.jar" }) - testJobPropTriggersChange(t, func(app *v1alpha1.FlinkApplication) { + testJobPropTriggersChange(t, func(app *v1beta1.FlinkApplication) { app.Spec.ProgramArgs = "--test-change" }) - testJobPropTriggersChange(t, func(app *v1alpha1.FlinkApplication) { + testJobPropTriggersChange(t, func(app *v1beta1.FlinkApplication) { app.Spec.EntryClass = "com.another.Class" }) } @@ -376,10 +376,10 @@ func TestCreateCluster(t *testing.T) { mockJobManager := flinkControllerForTest.jobManager.(*mock.JobManagerController) mockTaskManager := flinkControllerForTest.taskManager.(*mock.TaskManagerController) - mockJobManager.CreateIfNotExistFunc = func(ctx context.Context, application *v1alpha1.FlinkApplication) (bool, error) { + mockJobManager.CreateIfNotExistFunc = func(ctx context.Context, application *v1beta1.FlinkApplication) (bool, error) { return true, nil } - mockTaskManager.CreateIfNotExistFunc = func(ctx context.Context, application *v1alpha1.FlinkApplication) (bool, error) { + mockTaskManager.CreateIfNotExistFunc = func(ctx context.Context, application *v1beta1.FlinkApplication) (bool, error) { return true, nil } err := flinkControllerForTest.CreateCluster(context.Background(), &flinkApp) @@ -392,10 +392,10 @@ func TestCreateClusterJmErr(t *testing.T) { mockJobManager := flinkControllerForTest.jobManager.(*mock.JobManagerController) mockTaskManager := flinkControllerForTest.taskManager.(*mock.TaskManagerController) - mockJobManager.CreateIfNotExistFunc = func(ctx context.Context, application *v1alpha1.FlinkApplication) (bool, error) { + mockJobManager.CreateIfNotExistFunc = func(ctx context.Context, application *v1beta1.FlinkApplication) (bool, error) { return false, errors.New("jm failed") } - mockTaskManager.CreateIfNotExistFunc = func(ctx context.Context, application *v1alpha1.FlinkApplication) (bool, error) { + mockTaskManager.CreateIfNotExistFunc = func(ctx context.Context, application *v1beta1.FlinkApplication) (bool, error) { assert.False(t, true) return false, nil } @@ -409,10 +409,10 @@ func TestCreateClusterTmErr(t *testing.T) { mockJobManager := flinkControllerForTest.jobManager.(*mock.JobManagerController) mockTaskManager := flinkControllerForTest.taskManager.(*mock.TaskManagerController) - mockJobManager.CreateIfNotExistFunc = func(ctx context.Context, application *v1alpha1.FlinkApplication) (bool, error) { + mockJobManager.CreateIfNotExistFunc = func(ctx context.Context, application *v1beta1.FlinkApplication) (bool, error) { return true, nil } - mockTaskManager.CreateIfNotExistFunc = func(ctx context.Context, application *v1alpha1.FlinkApplication) (bool, error) { + mockTaskManager.CreateIfNotExistFunc = func(ctx context.Context, application *v1beta1.FlinkApplication) (bool, error) { return false, errors.New("tm failed") } err := flinkControllerForTest.CreateCluster(context.Background(), &flinkApp) @@ -634,7 +634,7 @@ func TestClusterStatusUpdated(t *testing.T) { assert.Equal(t, int32(1), flinkApp.Status.ClusterStatus.NumberOfTaskSlots) assert.Equal(t, int32(0), flinkApp.Status.ClusterStatus.AvailableTaskSlots) assert.Equal(t, int32(1), flinkApp.Status.ClusterStatus.HealthyTaskManagers) - assert.Equal(t, v1alpha1.Green, flinkApp.Status.ClusterStatus.Health) + assert.Equal(t, v1beta1.Green, flinkApp.Status.ClusterStatus.Health) } @@ -644,7 +644,7 @@ func TestNoClusterStatusChange(t *testing.T) { flinkApp.Status.ClusterStatus.NumberOfTaskSlots = int32(1) flinkApp.Status.ClusterStatus.AvailableTaskSlots = int32(0) flinkApp.Status.ClusterStatus.HealthyTaskManagers = int32(1) - flinkApp.Status.ClusterStatus.Health = v1alpha1.Green + flinkApp.Status.ClusterStatus.Health = v1beta1.Green flinkApp.Status.ClusterStatus.NumberOfTaskManagers = int32(1) mockK8Cluster := flinkControllerForTest.k8Cluster.(*k8mock.K8Cluster) mockK8Cluster.GetDeploymentsWithLabelFunc = func(ctx context.Context, namespace string, labelMap map[string]string) (*v1.DeploymentList, error) { @@ -736,7 +736,7 @@ func TestHealthyTaskmanagers(t *testing.T) { assert.Equal(t, int32(1), flinkApp.Status.ClusterStatus.NumberOfTaskSlots) assert.Equal(t, int32(0), flinkApp.Status.ClusterStatus.AvailableTaskSlots) assert.Equal(t, int32(0), flinkApp.Status.ClusterStatus.HealthyTaskManagers) - assert.Equal(t, v1alpha1.Yellow, flinkApp.Status.ClusterStatus.Health) + assert.Equal(t, v1beta1.Yellow, flinkApp.Status.ClusterStatus.Health) } @@ -780,9 +780,9 @@ func TestJobStatusUpdated(t *testing.T) { _, err := flinkControllerForTest.CompareAndUpdateJobStatus(context.Background(), &flinkApp, "hash") assert.Nil(t, err) - assert.Equal(t, v1alpha1.Running, flinkApp.Status.JobStatus.State) + assert.Equal(t, v1beta1.Running, flinkApp.Status.JobStatus.State) assert.Equal(t, &expectedTime, flinkApp.Status.JobStatus.StartTime) - assert.Equal(t, v1alpha1.Green, flinkApp.Status.JobStatus.Health) + assert.Equal(t, v1beta1.Green, flinkApp.Status.JobStatus.Health) assert.Equal(t, int32(0), flinkApp.Status.JobStatus.FailedCheckpointCount) assert.Equal(t, int32(4), flinkApp.Status.JobStatus.CompletedCheckpointCount) @@ -800,13 +800,13 @@ func TestNoJobStatusChange(t *testing.T) { app1 := getFlinkTestApp() mockJmClient := flinkControllerForTest.flinkClient.(*clientMock.JobManagerClient) - app1.Status.JobStatus.State = v1alpha1.Running + app1.Status.JobStatus.State = v1beta1.Running app1.Status.JobStatus.StartTime = &metaTime app1.Status.JobStatus.LastCheckpointTime = &metaTime app1.Status.JobStatus.CompletedCheckpointCount = int32(4) app1.Status.JobStatus.JobRestartCount = int32(1) app1.Status.JobStatus.FailedCheckpointCount = int32(0) - app1.Status.JobStatus.Health = v1alpha1.Green + app1.Status.JobStatus.Health = v1beta1.Green app1.Status.JobStatus.RestoreTime = &metaTime app1.Status.JobStatus.RestorePath = "/test/externalpath" @@ -851,7 +851,7 @@ func TestGetAndUpdateJobStatusHealth(t *testing.T) { app1 := getFlinkTestApp() mockJmClient := flinkControllerForTest.flinkClient.(*clientMock.JobManagerClient) - app1.Status.JobStatus.State = v1alpha1.Failing + app1.Status.JobStatus.State = v1beta1.Failing app1.Status.JobStatus.LastFailingTime = &lastFailedTime mockJmClient.GetJobOverviewFunc = func(ctx context.Context, url string, jobID string) (*client.FlinkJobOverview, error) { @@ -877,6 +877,6 @@ func TestGetAndUpdateJobStatusHealth(t *testing.T) { assert.Nil(t, err) // Job is in a RUNNING state but was in a FAILING state in the last 1 minute, so we expect // JobStatus.Health to be Red - assert.Equal(t, app1.Status.JobStatus.Health, v1alpha1.Red) + assert.Equal(t, app1.Status.JobStatus.Health, v1beta1.Red) } diff --git a/pkg/controller/flink/ingress.go b/pkg/controller/flink/ingress.go index 259b4432..e45e4614 100644 --- a/pkg/controller/flink/ingress.go +++ b/pkg/controller/flink/ingress.go @@ -3,7 +3,7 @@ package flink import ( "regexp" - "github.com/lyft/flinkk8soperator/pkg/apis/app/v1alpha1" + flinkapp "github.com/lyft/flinkk8soperator/pkg/apis/app/v1beta1" "github.com/lyft/flinkk8soperator/pkg/controller/common" "github.com/lyft/flinkk8soperator/pkg/controller/config" "github.com/lyft/flinkk8soperator/pkg/controller/k8" @@ -22,7 +22,7 @@ func GetFlinkUIIngressURL(jobName string) string { return ReplaceJobURL(config.GetConfig().FlinkIngressURLFormat, jobName) } -func FetchJobManagerIngressCreateObj(app *v1alpha1.FlinkApplication) *v1beta1.Ingress { +func FetchJobManagerIngressCreateObj(app *flinkapp.FlinkApplication) *v1beta1.Ingress { podLabels := common.DuplicateMap(app.Labels) podLabels = common.CopyMap(podLabels, k8.GetAppLabel(app.Name)) diff --git a/pkg/controller/flink/job_manager_controller.go b/pkg/controller/flink/job_manager_controller.go index 33c2c118..4826fb62 100644 --- a/pkg/controller/flink/job_manager_controller.go +++ b/pkg/controller/flink/job_manager_controller.go @@ -4,7 +4,7 @@ import ( "context" "fmt" - "github.com/lyft/flinkk8soperator/pkg/apis/app/v1alpha1" + "github.com/lyft/flinkk8soperator/pkg/apis/app/v1beta1" "github.com/lyft/flinkk8soperator/pkg/controller/common" "github.com/lyft/flinkk8soperator/pkg/controller/config" "github.com/lyft/flinkk8soperator/pkg/controller/k8" @@ -40,12 +40,12 @@ const ( FlinkInternalMetricPortName = "metrics" ) -func VersionedJobManagerServiceName(app *v1alpha1.FlinkApplication, hash string) string { +func VersionedJobManagerServiceName(app *v1beta1.FlinkApplication, hash string) string { return fmt.Sprintf("%s-%s", app.Name, hash) } type JobManagerControllerInterface interface { - CreateIfNotExist(ctx context.Context, application *v1alpha1.FlinkApplication) (bool, error) + CreateIfNotExist(ctx context.Context, application *v1beta1.FlinkApplication) (bool, error) } func NewJobManagerController(k8sCluster k8.ClusterInterface, config config.RuntimeConfig) JobManagerControllerInterface { @@ -84,7 +84,7 @@ type jobManagerMetrics struct { ingressCreationFailure labeled.Counter } -func (j *JobManagerController) CreateIfNotExist(ctx context.Context, application *v1alpha1.FlinkApplication) (bool, error) { +func (j *JobManagerController) CreateIfNotExist(ctx context.Context, application *v1beta1.FlinkApplication) (bool, error) { hash := HashForApplication(application) newlyCreated := false @@ -165,17 +165,17 @@ var JobManagerDefaultResources = coreV1.ResourceRequirements{ }, } -func getJobManagerPodName(application *v1alpha1.FlinkApplication, hash string) string { +func getJobManagerPodName(application *v1beta1.FlinkApplication, hash string) string { applicationName := application.Name return fmt.Sprintf(JobManagerPodNameFormat, applicationName, hash) } -func getJobManagerName(application *v1alpha1.FlinkApplication, hash string) string { +func getJobManagerName(application *v1beta1.FlinkApplication, hash string) string { applicationName := application.Name return fmt.Sprintf(JobManagerNameFormat, applicationName, hash) } -func FetchJobManagerServiceCreateObj(app *v1alpha1.FlinkApplication, hash string) *coreV1.Service { +func FetchJobManagerServiceCreateObj(app *v1beta1.FlinkApplication, hash string) *coreV1.Service { jmServiceName := app.Name serviceLabels := getCommonAppLabels(app) serviceLabels[FlinkAppHash] = hash @@ -201,7 +201,7 @@ func FetchJobManagerServiceCreateObj(app *v1alpha1.FlinkApplication, hash string } } -func getJobManagerServicePorts(app *v1alpha1.FlinkApplication) []coreV1.ServicePort { +func getJobManagerServicePorts(app *v1beta1.FlinkApplication) []coreV1.ServicePort { ports := getJobManagerPorts(app) servicePorts := make([]coreV1.ServicePort, 0, len(ports)) for _, p := range ports { @@ -213,7 +213,7 @@ func getJobManagerServicePorts(app *v1alpha1.FlinkApplication) []coreV1.ServiceP return servicePorts } -func getJobManagerPorts(app *v1alpha1.FlinkApplication) []coreV1.ContainerPort { +func getJobManagerPorts(app *v1beta1.FlinkApplication) []coreV1.ContainerPort { return []coreV1.ContainerPort{ { Name: FlinkRPCPortName, @@ -238,7 +238,7 @@ func getJobManagerPorts(app *v1alpha1.FlinkApplication) []coreV1.ContainerPort { } } -func FetchJobManagerContainerObj(application *v1alpha1.FlinkApplication) *coreV1.Container { +func FetchJobManagerContainerObj(application *v1beta1.FlinkApplication) *coreV1.Container { jmConfig := application.Spec.JobManagerConfig resources := jmConfig.Resources if resources == nil { @@ -287,7 +287,7 @@ func DeploymentIsJobmanager(deployment *v1.Deployment) bool { // made very carefully. Any new version v' that causes DeploymentsEqual(v(x), v'(x)) to be false // will cause redeployments for all applications, and should be considered a breaking change that // requires a new version of the CRD. -func jobmanagerTemplate(app *v1alpha1.FlinkApplication) *v1.Deployment { +func jobmanagerTemplate(app *v1beta1.FlinkApplication) *v1.Deployment { labels := getCommonAppLabels(app) labels = common.CopyMap(labels, app.Labels) labels[FlinkDeploymentType] = FlinkDeploymentTypeJobmanager @@ -337,7 +337,7 @@ func jobmanagerTemplate(app *v1alpha1.FlinkApplication) *v1.Deployment { } } -func FetchJobMangerDeploymentCreateObj(app *v1alpha1.FlinkApplication, hash string) *v1.Deployment { +func FetchJobMangerDeploymentCreateObj(app *v1beta1.FlinkApplication, hash string) *v1.Deployment { template := jobmanagerTemplate(app.DeepCopy()) template.Name = getJobManagerName(app, hash) @@ -351,7 +351,7 @@ func FetchJobMangerDeploymentCreateObj(app *v1alpha1.FlinkApplication, hash stri return template } -func JobManagerDeploymentMatches(deployment *v1.Deployment, application *v1alpha1.FlinkApplication) bool { +func JobManagerDeploymentMatches(deployment *v1.Deployment, application *v1beta1.FlinkApplication) bool { deploymentFromApp := FetchJobMangerDeploymentCreateObj(application, HashForApplication(application)) return DeploymentsEqual(deploymentFromApp, deployment) } diff --git a/pkg/controller/flink/job_manager_controller_test.go b/pkg/controller/flink/job_manager_controller_test.go index 6aa683db..038fca87 100644 --- a/pkg/controller/flink/job_manager_controller_test.go +++ b/pkg/controller/flink/job_manager_controller_test.go @@ -77,7 +77,7 @@ func TestJobManagerCreateSuccess(t *testing.T) { assert.Equal(t, expectedLabels, deployment.Labels) assert.Equal(t, int32(1), *deployment.Spec.Replicas) assert.Equal(t, "app-name", deployment.OwnerReferences[0].Name) - assert.Equal(t, "flink.k8s.io/v1alpha1", deployment.OwnerReferences[0].APIVersion) + assert.Equal(t, "flink.k8s.io/v1beta1", deployment.OwnerReferences[0].APIVersion) assert.Equal(t, "FlinkApplication", deployment.OwnerReferences[0].Kind) assert.Equal(t, "blob.server.port: 6125\njobmanager.heap.size: 1536\n"+ @@ -151,7 +151,7 @@ func TestJobManagerHACreateSuccess(t *testing.T) { assert.Equal(t, expectedLabels, deployment.Labels) assert.Equal(t, int32(1), *deployment.Spec.Replicas) assert.Equal(t, "app-name", deployment.OwnerReferences[0].Name) - assert.Equal(t, "flink.k8s.io/v1alpha1", deployment.OwnerReferences[0].APIVersion) + assert.Equal(t, "flink.k8s.io/v1beta1", deployment.OwnerReferences[0].APIVersion) assert.Equal(t, "FlinkApplication", deployment.OwnerReferences[0].Kind) assert.Equal(t, "blob.server.port: 6125\nhigh-availability: zookeeper\njobmanager.heap.size: 1536\n"+ diff --git a/pkg/controller/flink/mock/mock_flink.go b/pkg/controller/flink/mock/mock_flink.go index a325f7cc..0690c6a7 100644 --- a/pkg/controller/flink/mock/mock_flink.go +++ b/pkg/controller/flink/mock/mock_flink.go @@ -3,26 +3,26 @@ package mock import ( "context" - "github.com/lyft/flinkk8soperator/pkg/apis/app/v1alpha1" + "github.com/lyft/flinkk8soperator/pkg/apis/app/v1beta1" "github.com/lyft/flinkk8soperator/pkg/controller/common" "github.com/lyft/flinkk8soperator/pkg/controller/flink/client" corev1 "k8s.io/api/core/v1" ) -type CreateClusterFunc func(ctx context.Context, application *v1alpha1.FlinkApplication) error -type DeleteOldResourcesForApp func(ctx context.Context, application *v1alpha1.FlinkApplication) error -type CancelWithSavepointFunc func(ctx context.Context, application *v1alpha1.FlinkApplication, hash string) (string, error) -type ForceCancelFunc func(ctx context.Context, application *v1alpha1.FlinkApplication, hash string) error -type StartFlinkJobFunc func(ctx context.Context, application *v1alpha1.FlinkApplication, hash string, +type CreateClusterFunc func(ctx context.Context, application *v1beta1.FlinkApplication) error +type DeleteOldResourcesForApp func(ctx context.Context, application *v1beta1.FlinkApplication) error +type CancelWithSavepointFunc func(ctx context.Context, application *v1beta1.FlinkApplication, hash string) (string, error) +type ForceCancelFunc func(ctx context.Context, application *v1beta1.FlinkApplication, hash string) error +type StartFlinkJobFunc func(ctx context.Context, application *v1beta1.FlinkApplication, hash string, jarName string, parallelism int32, entryClass string, programArgs string, allowNonRestoredState bool) (string, error) -type GetSavepointStatusFunc func(ctx context.Context, application *v1alpha1.FlinkApplication, hash string) (*client.SavepointResponse, error) -type IsClusterReadyFunc func(ctx context.Context, application *v1alpha1.FlinkApplication) (bool, error) -type IsServiceReadyFunc func(ctx context.Context, application *v1alpha1.FlinkApplication, hash string) (bool, error) -type GetJobsForApplicationFunc func(ctx context.Context, application *v1alpha1.FlinkApplication, hash string) ([]client.FlinkJob, error) -type GetCurrentDeploymentsForAppFunc func(ctx context.Context, application *v1alpha1.FlinkApplication) (*common.FlinkDeployment, error) -type FindExternalizedCheckpointFunc func(ctx context.Context, application *v1alpha1.FlinkApplication, hash string) (string, error) -type CompareAndUpdateClusterStatusFunc func(ctx context.Context, application *v1alpha1.FlinkApplication, hash string) (bool, error) -type CompareAndUpdateJobStatusFunc func(ctx context.Context, application *v1alpha1.FlinkApplication, hash string) (bool, error) +type GetSavepointStatusFunc func(ctx context.Context, application *v1beta1.FlinkApplication, hash string) (*client.SavepointResponse, error) +type IsClusterReadyFunc func(ctx context.Context, application *v1beta1.FlinkApplication) (bool, error) +type IsServiceReadyFunc func(ctx context.Context, application *v1beta1.FlinkApplication, hash string) (bool, error) +type GetJobsForApplicationFunc func(ctx context.Context, application *v1beta1.FlinkApplication, hash string) ([]client.FlinkJob, error) +type GetCurrentDeploymentsForAppFunc func(ctx context.Context, application *v1beta1.FlinkApplication) (*common.FlinkDeployment, error) +type FindExternalizedCheckpointFunc func(ctx context.Context, application *v1beta1.FlinkApplication, hash string) (string, error) +type CompareAndUpdateClusterStatusFunc func(ctx context.Context, application *v1beta1.FlinkApplication, hash string) (bool, error) +type CompareAndUpdateJobStatusFunc func(ctx context.Context, application *v1beta1.FlinkApplication, hash string) (bool, error) type FlinkController struct { CreateClusterFunc CreateClusterFunc @@ -41,42 +41,42 @@ type FlinkController struct { CompareAndUpdateJobStatusFunc CompareAndUpdateJobStatusFunc } -func (m *FlinkController) GetCurrentDeploymentsForApp(ctx context.Context, application *v1alpha1.FlinkApplication) (*common.FlinkDeployment, error) { +func (m *FlinkController) GetCurrentDeploymentsForApp(ctx context.Context, application *v1beta1.FlinkApplication) (*common.FlinkDeployment, error) { if m.GetCurrentDeploymentsForAppFunc != nil { return m.GetCurrentDeploymentsForAppFunc(ctx, application) } return nil, nil } -func (m *FlinkController) DeleteOldResourcesForApp(ctx context.Context, application *v1alpha1.FlinkApplication) error { +func (m *FlinkController) DeleteOldResourcesForApp(ctx context.Context, application *v1beta1.FlinkApplication) error { if m.DeleteOldResourcesForAppFunc != nil { return m.DeleteOldResourcesForAppFunc(ctx, application) } return nil } -func (m *FlinkController) CreateCluster(ctx context.Context, application *v1alpha1.FlinkApplication) error { +func (m *FlinkController) CreateCluster(ctx context.Context, application *v1beta1.FlinkApplication) error { if m.CreateClusterFunc != nil { return m.CreateClusterFunc(ctx, application) } return nil } -func (m *FlinkController) CancelWithSavepoint(ctx context.Context, application *v1alpha1.FlinkApplication, hash string) (string, error) { +func (m *FlinkController) CancelWithSavepoint(ctx context.Context, application *v1beta1.FlinkApplication, hash string) (string, error) { if m.CancelWithSavepointFunc != nil { return m.CancelWithSavepointFunc(ctx, application, hash) } return "", nil } -func (m *FlinkController) ForceCancel(ctx context.Context, application *v1alpha1.FlinkApplication, hash string) error { +func (m *FlinkController) ForceCancel(ctx context.Context, application *v1beta1.FlinkApplication, hash string) error { if m.ForceCancelFunc != nil { return m.ForceCancelFunc(ctx, application, hash) } return nil } -func (m *FlinkController) StartFlinkJob(ctx context.Context, application *v1alpha1.FlinkApplication, hash string, +func (m *FlinkController) StartFlinkJob(ctx context.Context, application *v1beta1.FlinkApplication, hash string, jarName string, parallelism int32, entryClass string, programArgs string, allowNonRestoredState bool) (string, error) { if m.StartFlinkJobFunc != nil { return m.StartFlinkJobFunc(ctx, application, hash, jarName, parallelism, entryClass, programArgs, allowNonRestoredState) @@ -84,42 +84,42 @@ func (m *FlinkController) StartFlinkJob(ctx context.Context, application *v1alph return "", nil } -func (m *FlinkController) GetSavepointStatus(ctx context.Context, application *v1alpha1.FlinkApplication, hash string) (*client.SavepointResponse, error) { +func (m *FlinkController) GetSavepointStatus(ctx context.Context, application *v1beta1.FlinkApplication, hash string) (*client.SavepointResponse, error) { if m.GetSavepointStatusFunc != nil { return m.GetSavepointStatusFunc(ctx, application, hash) } return nil, nil } -func (m *FlinkController) IsClusterReady(ctx context.Context, application *v1alpha1.FlinkApplication) (bool, error) { +func (m *FlinkController) IsClusterReady(ctx context.Context, application *v1beta1.FlinkApplication) (bool, error) { if m.IsClusterReadyFunc != nil { return m.IsClusterReadyFunc(ctx, application) } return false, nil } -func (m *FlinkController) IsServiceReady(ctx context.Context, application *v1alpha1.FlinkApplication, hash string) (bool, error) { +func (m *FlinkController) IsServiceReady(ctx context.Context, application *v1beta1.FlinkApplication, hash string) (bool, error) { if m.IsServiceReadyFunc != nil { return m.IsServiceReadyFunc(ctx, application, hash) } return false, nil } -func (m *FlinkController) GetJobsForApplication(ctx context.Context, application *v1alpha1.FlinkApplication, hash string) ([]client.FlinkJob, error) { +func (m *FlinkController) GetJobsForApplication(ctx context.Context, application *v1beta1.FlinkApplication, hash string) ([]client.FlinkJob, error) { if m.GetJobsForApplicationFunc != nil { return m.GetJobsForApplicationFunc(ctx, application, hash) } return nil, nil } -func (m *FlinkController) FindExternalizedCheckpoint(ctx context.Context, application *v1alpha1.FlinkApplication, hash string) (string, error) { +func (m *FlinkController) FindExternalizedCheckpoint(ctx context.Context, application *v1beta1.FlinkApplication, hash string) (string, error) { if m.FindExternalizedCheckpointFunc != nil { return m.FindExternalizedCheckpointFunc(ctx, application, hash) } return "", nil } -func (m *FlinkController) LogEvent(ctx context.Context, app *v1alpha1.FlinkApplication, eventType string, reason string, message string) { +func (m *FlinkController) LogEvent(ctx context.Context, app *v1beta1.FlinkApplication, eventType string, reason string, message string) { m.Events = append(m.Events, corev1.Event{ InvolvedObject: corev1.ObjectReference{ Kind: app.Kind, @@ -132,7 +132,7 @@ func (m *FlinkController) LogEvent(ctx context.Context, app *v1alpha1.FlinkAppli }) } -func (m *FlinkController) CompareAndUpdateClusterStatus(ctx context.Context, application *v1alpha1.FlinkApplication, hash string) (bool, error) { +func (m *FlinkController) CompareAndUpdateClusterStatus(ctx context.Context, application *v1beta1.FlinkApplication, hash string) (bool, error) { if m.CompareAndUpdateClusterStatusFunc != nil { return m.CompareAndUpdateClusterStatusFunc(ctx, application, hash) } @@ -140,7 +140,7 @@ func (m *FlinkController) CompareAndUpdateClusterStatus(ctx context.Context, app return false, nil } -func (m *FlinkController) CompareAndUpdateJobStatus(ctx context.Context, app *v1alpha1.FlinkApplication, hash string) (bool, error) { +func (m *FlinkController) CompareAndUpdateJobStatus(ctx context.Context, app *v1beta1.FlinkApplication, hash string) (bool, error) { if m.CompareAndUpdateJobStatusFunc != nil { return m.CompareAndUpdateJobStatusFunc(ctx, app, hash) } diff --git a/pkg/controller/flink/mock/mock_job_manager_controller.go b/pkg/controller/flink/mock/mock_job_manager_controller.go index af74fa07..7814f37d 100644 --- a/pkg/controller/flink/mock/mock_job_manager_controller.go +++ b/pkg/controller/flink/mock/mock_job_manager_controller.go @@ -3,7 +3,7 @@ package mock import ( "context" - "github.com/lyft/flinkk8soperator/pkg/apis/app/v1alpha1" + "github.com/lyft/flinkk8soperator/pkg/apis/app/v1beta1" ) type JobManagerController struct { @@ -12,7 +12,7 @@ type JobManagerController struct { func (m *JobManagerController) CreateIfNotExist( ctx context.Context, - application *v1alpha1.FlinkApplication) (bool, error) { + application *v1beta1.FlinkApplication) (bool, error) { if m.CreateIfNotExistFunc != nil { return m.CreateIfNotExistFunc(ctx, application) } diff --git a/pkg/controller/flink/mock/mock_task_manager_controller.go b/pkg/controller/flink/mock/mock_task_manager_controller.go index 06275e98..6857b088 100644 --- a/pkg/controller/flink/mock/mock_task_manager_controller.go +++ b/pkg/controller/flink/mock/mock_task_manager_controller.go @@ -3,17 +3,17 @@ package mock import ( "context" - "github.com/lyft/flinkk8soperator/pkg/apis/app/v1alpha1" + "github.com/lyft/flinkk8soperator/pkg/apis/app/v1beta1" ) -type CreateIfNotExistFunc func(ctx context.Context, application *v1alpha1.FlinkApplication) (bool, error) +type CreateIfNotExistFunc func(ctx context.Context, application *v1beta1.FlinkApplication) (bool, error) type TaskManagerController struct { CreateIfNotExistFunc CreateIfNotExistFunc } func (m *TaskManagerController) CreateIfNotExist( - ctx context.Context, application *v1alpha1.FlinkApplication) (bool, error) { + ctx context.Context, application *v1beta1.FlinkApplication) (bool, error) { if m.CreateIfNotExistFunc != nil { return m.CreateIfNotExistFunc(ctx, application) } diff --git a/pkg/controller/flink/task_manager_controller.go b/pkg/controller/flink/task_manager_controller.go index 82a02a35..69d56584 100644 --- a/pkg/controller/flink/task_manager_controller.go +++ b/pkg/controller/flink/task_manager_controller.go @@ -5,7 +5,7 @@ import ( "fmt" "math" - "github.com/lyft/flinkk8soperator/pkg/apis/app/v1alpha1" + "github.com/lyft/flinkk8soperator/pkg/apis/app/v1beta1" "github.com/lyft/flinkk8soperator/pkg/controller/common" "github.com/lyft/flinkk8soperator/pkg/controller/config" "github.com/lyft/flinkk8soperator/pkg/controller/k8" @@ -28,7 +28,7 @@ const ( ) type TaskManagerControllerInterface interface { - CreateIfNotExist(ctx context.Context, application *v1alpha1.FlinkApplication) (bool, error) + CreateIfNotExist(ctx context.Context, application *v1beta1.FlinkApplication) (bool, error) } func NewTaskManagerController(k8sCluster k8.ClusterInterface, config config.RuntimeConfig) TaskManagerControllerInterface { @@ -70,7 +70,7 @@ var TaskManagerDefaultResources = coreV1.ResourceRequirements{ }, } -func (t *TaskManagerController) CreateIfNotExist(ctx context.Context, application *v1alpha1.FlinkApplication) (bool, error) { +func (t *TaskManagerController) CreateIfNotExist(ctx context.Context, application *v1beta1.FlinkApplication) (bool, error) { hash := HashForApplication(application) taskManagerDeployment := FetchTaskMangerDeploymentCreateObj(application, hash) @@ -90,7 +90,7 @@ func (t *TaskManagerController) CreateIfNotExist(ctx context.Context, applicatio return false, nil } -func GetTaskManagerPorts(app *v1alpha1.FlinkApplication) []coreV1.ContainerPort { +func GetTaskManagerPorts(app *v1beta1.FlinkApplication) []coreV1.ContainerPort { return []coreV1.ContainerPort{ { Name: FlinkRPCPortName, @@ -111,7 +111,7 @@ func GetTaskManagerPorts(app *v1alpha1.FlinkApplication) []coreV1.ContainerPort } } -func FetchTaskManagerContainerObj(application *v1alpha1.FlinkApplication) *coreV1.Container { +func FetchTaskManagerContainerObj(application *v1beta1.FlinkApplication) *coreV1.Container { tmConfig := application.Spec.TaskManagerConfig ports := GetTaskManagerPorts(application) resources := tmConfig.Resources @@ -140,17 +140,17 @@ func FetchTaskManagerContainerObj(application *v1alpha1.FlinkApplication) *coreV } } -func getTaskManagerPodName(application *v1alpha1.FlinkApplication, hash string) string { +func getTaskManagerPodName(application *v1beta1.FlinkApplication, hash string) string { applicationName := application.Name return fmt.Sprintf(TaskManagerPodNameFormat, applicationName, hash) } -func getTaskManagerName(application *v1alpha1.FlinkApplication, hash string) string { +func getTaskManagerName(application *v1beta1.FlinkApplication, hash string) string { applicationName := application.Name return fmt.Sprintf(TaskManagerNameFormat, applicationName, hash) } -func computeTaskManagerReplicas(application *v1alpha1.FlinkApplication) int32 { +func computeTaskManagerReplicas(application *v1beta1.FlinkApplication) int32 { slots := getTaskmanagerSlots(application) parallelism := application.Spec.Parallelism return int32(math.Ceil(float64(parallelism) / float64(slots))) @@ -164,7 +164,7 @@ func DeploymentIsTaskmanager(deployment *v1.Deployment) bool { // made very carefully. Any new version v' that causes DeploymentsEqual(v(x), v'(x)) to be false // will cause redeployments for all applications, and should be considered a breaking change that // requires a new version of the CRD. -func taskmanagerTemplate(app *v1alpha1.FlinkApplication) *v1.Deployment { +func taskmanagerTemplate(app *v1beta1.FlinkApplication) *v1.Deployment { labels := getCommonAppLabels(app) labels = common.CopyMap(labels, app.Labels) labels[FlinkDeploymentType] = FlinkDeploymentTypeTaskmanager @@ -214,7 +214,7 @@ func taskmanagerTemplate(app *v1alpha1.FlinkApplication) *v1.Deployment { } } -func FetchTaskMangerDeploymentCreateObj(app *v1alpha1.FlinkApplication, hash string) *v1.Deployment { +func FetchTaskMangerDeploymentCreateObj(app *v1beta1.FlinkApplication, hash string) *v1.Deployment { template := taskmanagerTemplate(app.DeepCopy()) template.Name = getTaskManagerName(app, hash) @@ -228,7 +228,7 @@ func FetchTaskMangerDeploymentCreateObj(app *v1alpha1.FlinkApplication, hash str return template } -func TaskManagerDeploymentMatches(deployment *v1.Deployment, application *v1alpha1.FlinkApplication) bool { +func TaskManagerDeploymentMatches(deployment *v1.Deployment, application *v1beta1.FlinkApplication) bool { deploymentFromApp := FetchTaskMangerDeploymentCreateObj(application, HashForApplication(application)) return DeploymentsEqual(deploymentFromApp, deployment) } diff --git a/pkg/controller/flink/task_manager_controller_test.go b/pkg/controller/flink/task_manager_controller_test.go index 51b62f18..3198162e 100644 --- a/pkg/controller/flink/task_manager_controller_test.go +++ b/pkg/controller/flink/task_manager_controller_test.go @@ -8,7 +8,7 @@ import ( "context" - "github.com/lyft/flinkk8soperator/pkg/apis/app/v1alpha1" + "github.com/lyft/flinkk8soperator/pkg/apis/app/v1beta1" "github.com/lyft/flinkk8soperator/pkg/controller/common" "github.com/lyft/flytestdlib/promutils/labeled" "github.com/pkg/errors" @@ -30,7 +30,7 @@ func getTMControllerForTest() TaskManagerController { } func TestComputeTaskManagerReplicas(t *testing.T) { - app := v1alpha1.FlinkApplication{} + app := v1beta1.FlinkApplication{} taskSlots := int32(4) app.Spec.TaskManagerConfig.TaskSlots = &taskSlots app.Spec.Parallelism = 9 diff --git a/pkg/controller/flinkapplication/controller.go b/pkg/controller/flinkapplication/controller.go index a03fc913..54513b78 100644 --- a/pkg/controller/flinkapplication/controller.go +++ b/pkg/controller/flinkapplication/controller.go @@ -6,7 +6,7 @@ import ( "github.com/lyft/flytestdlib/promutils" "github.com/lyft/flytestdlib/promutils/labeled" - "github.com/lyft/flinkk8soperator/pkg/apis/app/v1alpha1" + "github.com/lyft/flinkk8soperator/pkg/apis/app/v1beta1" "github.com/lyft/flinkk8soperator/pkg/controller/config" "sigs.k8s.io/controller-runtime/pkg/controller" @@ -87,11 +87,11 @@ func (r *ReconcileFlinkApplication) Reconcile(request reconcile.Request) (reconc ctx = contextutils.WithNamespace(ctx, request.Namespace) ctx = contextutils.WithAppName(ctx, request.Name) typeMeta := metaV1.TypeMeta{ - Kind: v1alpha1.FlinkApplicationKind, - APIVersion: v1alpha1.SchemeGroupVersion.String(), + Kind: v1beta1.FlinkApplicationKind, + APIVersion: v1beta1.SchemeGroupVersion.String(), } // Fetch the FlinkApplication instance - instance := &v1alpha1.FlinkApplication{ + instance := &v1beta1.FlinkApplication{ TypeMeta: typeMeta, } @@ -140,7 +140,7 @@ func Add(ctx context.Context, mgr manager.Manager, cfg config.RuntimeConfig) err return err } - if err = c.Watch(&source.Kind{Type: &v1alpha1.FlinkApplication{}}, &handler.EnqueueRequestForObject{}); err != nil { + if err = c.Watch(&source.Kind{Type: &v1beta1.FlinkApplication{}}, &handler.EnqueueRequestForObject{}); err != nil { return err } @@ -157,8 +157,8 @@ func Add(ctx context.Context, mgr manager.Manager, cfg config.RuntimeConfig) err func isOwnedByFlinkApplication(ownerReferences []metaV1.OwnerReference) bool { for _, ownerReference := range ownerReferences { - if ownerReference.APIVersion == v1alpha1.SchemeGroupVersion.String() && - ownerReference.Kind == v1alpha1.FlinkApplicationKind { + if ownerReference.APIVersion == v1beta1.SchemeGroupVersion.String() && + ownerReference.Kind == v1beta1.FlinkApplicationKind { return true } } diff --git a/pkg/controller/flinkapplication/flink_state_machine.go b/pkg/controller/flinkapplication/flink_state_machine.go index 0dfb9118..e76a02ec 100644 --- a/pkg/controller/flinkapplication/flink_state_machine.go +++ b/pkg/controller/flinkapplication/flink_state_machine.go @@ -10,7 +10,7 @@ import ( "fmt" - "github.com/lyft/flinkk8soperator/pkg/apis/app/v1alpha1" + "github.com/lyft/flinkk8soperator/pkg/apis/app/v1beta1" "github.com/lyft/flinkk8soperator/pkg/controller/config" "github.com/lyft/flinkk8soperator/pkg/controller/flink" "github.com/lyft/flinkk8soperator/pkg/controller/flink/client" @@ -32,7 +32,7 @@ const ( // The core state machine that manages Flink clusters and jobs. See docs/state_machine.md for a description of the // states and transitions. type FlinkHandlerInterface interface { - Handle(ctx context.Context, application *v1alpha1.FlinkApplication) error + Handle(ctx context.Context, application *v1beta1.FlinkApplication) error } type FlinkStateMachine struct { @@ -45,18 +45,18 @@ type FlinkStateMachine struct { type stateMachineMetrics struct { scope promutils.Scope - stateMachineHandlePhaseMap map[v1alpha1.FlinkApplicationPhase]labeled.StopWatch - stateMachineHandleSuccessPhaseMap map[v1alpha1.FlinkApplicationPhase]labeled.StopWatch - errorCounterPhaseMap map[v1alpha1.FlinkApplicationPhase]labeled.Counter + stateMachineHandlePhaseMap map[v1beta1.FlinkApplicationPhase]labeled.StopWatch + stateMachineHandleSuccessPhaseMap map[v1beta1.FlinkApplicationPhase]labeled.StopWatch + errorCounterPhaseMap map[v1beta1.FlinkApplicationPhase]labeled.Counter } func newStateMachineMetrics(scope promutils.Scope) *stateMachineMetrics { stateMachineScope := scope.NewSubScope("state_machine") - stateMachineHandlePhaseMap := map[v1alpha1.FlinkApplicationPhase]labeled.StopWatch{} - stateMachineHandleSuccessPhaseMap := map[v1alpha1.FlinkApplicationPhase]labeled.StopWatch{} - errorCounterPhaseMap := map[v1alpha1.FlinkApplicationPhase]labeled.Counter{} + stateMachineHandlePhaseMap := map[v1beta1.FlinkApplicationPhase]labeled.StopWatch{} + stateMachineHandleSuccessPhaseMap := map[v1beta1.FlinkApplicationPhase]labeled.StopWatch{} + errorCounterPhaseMap := map[v1beta1.FlinkApplicationPhase]labeled.Counter{} - for _, phase := range v1alpha1.FlinkApplicationPhases { + for _, phase := range v1beta1.FlinkApplicationPhases { phaseName := phase.VerboseString() stateMachineHandleSuccessPhaseMap[phase] = labeled.NewStopWatch(phaseName+"_"+"handle_time_success", fmt.Sprintf("Total time to handle the %s application state on success", phaseName), time.Millisecond, stateMachineScope) @@ -73,12 +73,12 @@ func newStateMachineMetrics(scope promutils.Scope) *stateMachineMetrics { } } -func (s *FlinkStateMachine) updateApplicationPhase(application *v1alpha1.FlinkApplication, phase v1alpha1.FlinkApplicationPhase) { +func (s *FlinkStateMachine) updateApplicationPhase(application *v1beta1.FlinkApplication, phase v1beta1.FlinkApplicationPhase) { application.Status.Phase = phase } -func (s *FlinkStateMachine) shouldRollback(ctx context.Context, application *v1alpha1.FlinkApplication) bool { - if application.Spec.ForceRollback && application.Status.Phase != v1alpha1.FlinkApplicationRollingBackJob { +func (s *FlinkStateMachine) shouldRollback(ctx context.Context, application *v1beta1.FlinkApplication) bool { + if application.Spec.ForceRollback && application.Status.Phase != v1beta1.FlinkApplicationRollingBackJob { return true } if application.Status.DeployHash == "" { @@ -115,7 +115,7 @@ func (s *FlinkStateMachine) shouldRollback(ctx context.Context, application *v1a return false } -func (s *FlinkStateMachine) Handle(ctx context.Context, application *v1alpha1.FlinkApplication) error { +func (s *FlinkStateMachine) Handle(ctx context.Context, application *v1beta1.FlinkApplication) error { currentPhase := application.Status.Phase if _, ok := s.metrics.stateMachineHandlePhaseMap[currentPhase]; !ok { errMsg := fmt.Sprintf("Invalid state %s for the application", currentPhase) @@ -145,41 +145,41 @@ func (s *FlinkStateMachine) Handle(ctx context.Context, application *v1alpha1.Fl return err } -func (s *FlinkStateMachine) handle(ctx context.Context, application *v1alpha1.FlinkApplication) (bool, error) { +func (s *FlinkStateMachine) handle(ctx context.Context, application *v1beta1.FlinkApplication) (bool, error) { var appErr error updateApplication := false updateLastSeenError := false appPhase := application.Status.Phase - if !application.ObjectMeta.DeletionTimestamp.IsZero() && appPhase != v1alpha1.FlinkApplicationDeleting { - s.updateApplicationPhase(application, v1alpha1.FlinkApplicationDeleting) + if !application.ObjectMeta.DeletionTimestamp.IsZero() && appPhase != v1beta1.FlinkApplicationDeleting { + s.updateApplicationPhase(application, v1beta1.FlinkApplicationDeleting) // Always perform a single application update per callback return applicationChanged, nil } if s.IsTimeToHandlePhase(application) { - if !v1alpha1.IsRunningPhase(application.Status.Phase) { + if !v1beta1.IsRunningPhase(application.Status.Phase) { logger.Infof(ctx, "Handling state for application") } switch application.Status.Phase { - case v1alpha1.FlinkApplicationNew, v1alpha1.FlinkApplicationUpdating: + case v1beta1.FlinkApplicationNew, v1beta1.FlinkApplicationUpdating: // Currently just transitions to the next state updateApplication, appErr = s.handleNewOrUpdating(ctx, application) - case v1alpha1.FlinkApplicationClusterStarting: + case v1beta1.FlinkApplicationClusterStarting: updateApplication, appErr = s.handleClusterStarting(ctx, application) - case v1alpha1.FlinkApplicationSubmittingJob: + case v1beta1.FlinkApplicationSubmittingJob: updateApplication, appErr = s.handleSubmittingJob(ctx, application) - case v1alpha1.FlinkApplicationRunning, v1alpha1.FlinkApplicationDeployFailed: + case v1beta1.FlinkApplicationRunning, v1beta1.FlinkApplicationDeployFailed: updateApplication, appErr = s.handleApplicationRunning(ctx, application) - case v1alpha1.FlinkApplicationSavepointing: + case v1beta1.FlinkApplicationSavepointing: updateApplication, appErr = s.handleApplicationSavepointing(ctx, application) - case v1alpha1.FlinkApplicationRollingBackJob: + case v1beta1.FlinkApplicationRollingBackJob: updateApplication, appErr = s.handleRollingBack(ctx, application) - case v1alpha1.FlinkApplicationDeleting: + case v1beta1.FlinkApplicationDeleting: updateApplication, appErr = s.handleApplicationDeleting(ctx, application) } - if !v1alpha1.IsRunningPhase(appPhase) { + if !v1beta1.IsRunningPhase(appPhase) { // Only update LastSeenError and thereby invoke error handling logic for // non-Running phases updateLastSeenError = s.compareAndUpdateError(application, appErr) @@ -190,7 +190,7 @@ func (s *FlinkStateMachine) handle(ctx context.Context, application *v1alpha1.Fl return updateApplication || updateLastSeenError, appErr } -func (s *FlinkStateMachine) IsTimeToHandlePhase(application *v1alpha1.FlinkApplication) bool { +func (s *FlinkStateMachine) IsTimeToHandlePhase(application *v1beta1.FlinkApplication) bool { lastSeenError := application.Status.LastSeenError if application.Status.LastSeenError == nil || !s.retryHandler.IsErrorRetryable(application.Status.LastSeenError) { return true @@ -213,7 +213,7 @@ func (s *FlinkStateMachine) IsTimeToHandlePhase(application *v1alpha1.FlinkAppli } // In this state we create a new cluster, either due to an entirely new FlinkApplication or due to an update. -func (s *FlinkStateMachine) handleNewOrUpdating(ctx context.Context, application *v1alpha1.FlinkApplication) (bool, error) { +func (s *FlinkStateMachine) handleNewOrUpdating(ctx context.Context, application *v1beta1.FlinkApplication) (bool, error) { // TODO: add up-front validation on the FlinkApplication resource if s.shouldRollback(ctx, application) { // we've failed to make progress; move to deploy failed @@ -227,11 +227,11 @@ func (s *FlinkStateMachine) handleNewOrUpdating(ctx context.Context, application return applicationUnchanged, err } - s.updateApplicationPhase(application, v1alpha1.FlinkApplicationClusterStarting) + s.updateApplicationPhase(application, v1beta1.FlinkApplicationClusterStarting) return applicationChanged, nil } -func (s *FlinkStateMachine) deployFailed(ctx context.Context, app *v1alpha1.FlinkApplication) (bool, error) { +func (s *FlinkStateMachine) deployFailed(ctx context.Context, app *v1beta1.FlinkApplication) (bool, error) { hash := flink.HashForApplication(app) s.flinkController.LogEvent(ctx, app, corev1.EventTypeWarning, "RolledBackDeploy", fmt.Sprintf("Successfull rolled back deploy %s", hash)) @@ -242,12 +242,12 @@ func (s *FlinkStateMachine) deployFailed(ctx context.Context, app *v1alpha1.Flin app.Status.LastSeenError = nil app.Status.RetryCount = 0 - s.updateApplicationPhase(app, v1alpha1.FlinkApplicationDeployFailed) + s.updateApplicationPhase(app, v1beta1.FlinkApplicationDeployFailed) return applicationChanged, nil } // Create the underlying Kubernetes objects for the new cluster -func (s *FlinkStateMachine) handleClusterStarting(ctx context.Context, application *v1alpha1.FlinkApplication) (bool, error) { +func (s *FlinkStateMachine) handleClusterStarting(ctx context.Context, application *v1beta1.FlinkApplication) (bool, error) { if s.shouldRollback(ctx, application) { // we've failed to make progress; move to deploy failed // TODO: this will need different logic in single mode @@ -265,14 +265,14 @@ func (s *FlinkStateMachine) handleClusterStarting(ctx context.Context, applicati logger.Infof(ctx, "Flink cluster has started successfully") // TODO: in single mode move to submitting job - s.updateApplicationPhase(application, v1alpha1.FlinkApplicationSavepointing) + s.updateApplicationPhase(application, v1beta1.FlinkApplicationSavepointing) return applicationChanged, nil } -func (s *FlinkStateMachine) handleApplicationSavepointing(ctx context.Context, application *v1alpha1.FlinkApplication) (bool, error) { +func (s *FlinkStateMachine) handleApplicationSavepointing(ctx context.Context, application *v1beta1.FlinkApplication) (bool, error) { // we've already savepointed (or this is our first deploy), continue on if application.Spec.SavepointInfo.SavepointLocation != "" || application.Status.DeployHash == "" { - s.updateApplicationPhase(application, v1alpha1.FlinkApplicationSubmittingJob) + s.updateApplicationPhase(application, v1beta1.FlinkApplicationSubmittingJob) return applicationChanged, nil } @@ -338,14 +338,14 @@ func (s *FlinkStateMachine) handleApplicationSavepointing(ctx context.Context, a if restorePath != "" { application.Spec.SavepointInfo.SavepointLocation = restorePath - s.updateApplicationPhase(application, v1alpha1.FlinkApplicationSubmittingJob) + s.updateApplicationPhase(application, v1beta1.FlinkApplicationSubmittingJob) return applicationChanged, nil } return applicationUnchanged, nil } -func (s *FlinkStateMachine) submitJobIfNeeded(ctx context.Context, app *v1alpha1.FlinkApplication, hash string, +func (s *FlinkStateMachine) submitJobIfNeeded(ctx context.Context, app *v1beta1.FlinkApplication, hash string, jarName string, parallelism int32, entryClass string, programArgs string, allowNonRestoredState bool) (*client.FlinkJob, error) { isReady, _ := s.flinkController.IsServiceReady(ctx, app, hash) // Ignore errors @@ -389,7 +389,7 @@ func (s *FlinkStateMachine) submitJobIfNeeded(ctx context.Context, app *v1alpha1 return activeJob, nil } -func (s *FlinkStateMachine) updateGenericService(ctx context.Context, app *v1alpha1.FlinkApplication, newHash string) error { +func (s *FlinkStateMachine) updateGenericService(ctx context.Context, app *v1beta1.FlinkApplication, newHash string) error { service, err := s.k8Cluster.GetService(ctx, app.Namespace, app.Name) if err != nil { return err @@ -413,10 +413,10 @@ func (s *FlinkStateMachine) updateGenericService(ctx context.Context, app *v1alp return nil } -func (s *FlinkStateMachine) handleSubmittingJob(ctx context.Context, app *v1alpha1.FlinkApplication) (bool, error) { +func (s *FlinkStateMachine) handleSubmittingJob(ctx context.Context, app *v1beta1.FlinkApplication) (bool, error) { if s.shouldRollback(ctx, app) { // Something's gone wrong; roll back - s.updateApplicationPhase(app, v1alpha1.FlinkApplicationRollingBackJob) + s.updateApplicationPhase(app, v1beta1.FlinkApplicationRollingBackJob) return applicationChanged, nil } @@ -441,7 +441,7 @@ func (s *FlinkStateMachine) handleSubmittingJob(ctx context.Context, app *v1alph if activeJob != nil && activeJob.Status == client.Running { // Clear the savepoint info - app.Spec.SavepointInfo = v1alpha1.SavepointInfo{} + app.Spec.SavepointInfo = v1beta1.SavepointInfo{} // Update the application status with the running job info app.Status.DeployHash = hash app.Status.JobStatus.JarName = app.Spec.JarName @@ -450,7 +450,7 @@ func (s *FlinkStateMachine) handleSubmittingJob(ctx context.Context, app *v1alph app.Status.JobStatus.ProgramArgs = app.Spec.ProgramArgs app.Status.JobStatus.AllowNonRestoredState = app.Spec.AllowNonRestoredState - s.updateApplicationPhase(app, v1alpha1.FlinkApplicationRunning) + s.updateApplicationPhase(app, v1beta1.FlinkApplicationRunning) return applicationChanged, nil } @@ -459,7 +459,7 @@ func (s *FlinkStateMachine) handleSubmittingJob(ctx context.Context, app *v1alph // Something has gone wrong during the update, post job-cancellation (and cluster tear-down in single mode). We need // to try to get things back into a working state -func (s *FlinkStateMachine) handleRollingBack(ctx context.Context, app *v1alpha1.FlinkApplication) (bool, error) { +func (s *FlinkStateMachine) handleRollingBack(ctx context.Context, app *v1beta1.FlinkApplication) (bool, error) { if s.shouldRollback(ctx, app) { // we've failed in our roll back attempt (presumably because something's now wrong with the original cluster) // move immediately to the DeployFailed state so that the user can recover. @@ -500,7 +500,7 @@ func (s *FlinkStateMachine) handleRollingBack(ctx context.Context, app *v1alpha1 } if activeJob != nil { - app.Spec.SavepointInfo = v1alpha1.SavepointInfo{} + app.Spec.SavepointInfo = v1beta1.SavepointInfo{} // move to the deploy failed state return s.deployFailed(ctx, app) } @@ -510,7 +510,7 @@ func (s *FlinkStateMachine) handleRollingBack(ctx context.Context, app *v1alpha1 // Check if the application is Running. // This is a stable state. Keep monitoring if the underlying CRD reflects the Flink cluster -func (s *FlinkStateMachine) handleApplicationRunning(ctx context.Context, application *v1alpha1.FlinkApplication) (bool, error) { +func (s *FlinkStateMachine) handleApplicationRunning(ctx context.Context, application *v1beta1.FlinkApplication) (bool, error) { jobs, err := s.flinkController.GetJobsForApplication(ctx, application, application.Status.DeployHash) if err != nil { // TODO: think more about this case @@ -537,7 +537,7 @@ func (s *FlinkStateMachine) handleApplicationRunning(ctx context.Context, applic if cur == nil { logger.Infof(ctx, "Application resource has changed. Moving to Updating") // TODO: handle single mode - s.updateApplicationPhase(application, v1alpha1.FlinkApplicationUpdating) + s.updateApplicationPhase(application, v1beta1.FlinkApplicationUpdating) return applicationChanged, nil } @@ -567,7 +567,7 @@ func (s *FlinkStateMachine) handleApplicationRunning(ctx context.Context, applic return applicationUnchanged, nil } -func (s *FlinkStateMachine) addFinalizerIfMissing(ctx context.Context, application *v1alpha1.FlinkApplication, finalizer string) error { +func (s *FlinkStateMachine) addFinalizerIfMissing(ctx context.Context, application *v1beta1.FlinkApplication, finalizer string) error { for _, f := range application.Finalizers { if f == finalizer { return nil @@ -590,7 +590,7 @@ func removeString(list []string, target string) []string { return ret } -func (s *FlinkStateMachine) clearFinalizers(app *v1alpha1.FlinkApplication) (bool, error) { +func (s *FlinkStateMachine) clearFinalizers(app *v1beta1.FlinkApplication) (bool, error) { app.Finalizers = removeString(app.Finalizers, jobFinalizer) return applicationChanged, nil } @@ -607,7 +607,7 @@ func jobFinished(jobs []client.FlinkJob, id string) bool { return true } -func (s *FlinkStateMachine) handleApplicationDeleting(ctx context.Context, app *v1alpha1.FlinkApplication) (bool, error) { +func (s *FlinkStateMachine) handleApplicationDeleting(ctx context.Context, app *v1beta1.FlinkApplication) (bool, error) { // There should be a way for the user to force deletion (e.g., if the job is failing and they can't // savepoint). However, this seems dangerous to do automatically. // If https://github.com/kubernetes/kubernetes/issues/56567 is fixed users will be able to use @@ -615,7 +615,7 @@ func (s *FlinkStateMachine) handleApplicationDeleting(ctx context.Context, app * // If the delete mode is none or there's no deployhash set (which means we failed to submit the job on the // first deploy) just delete the finalizer so the cluster can be torn down - if app.Spec.DeleteMode == v1alpha1.DeleteModeNone || app.Status.DeployHash == "" { + if app.Spec.DeleteMode == v1beta1.DeleteModeNone || app.Status.DeployHash == "" { return s.clearFinalizers(app) } @@ -632,10 +632,10 @@ func (s *FlinkStateMachine) handleApplicationDeleting(ctx context.Context, app * } switch app.Spec.DeleteMode { - case v1alpha1.DeleteModeForceCancel: + case v1beta1.DeleteModeForceCancel: logger.Infof(ctx, "Force cancelling job as part of cleanup") return applicationUnchanged, s.flinkController.ForceCancel(ctx, app, app.Status.DeployHash) - case v1alpha1.DeleteModeSavepoint, "": + case v1beta1.DeleteModeSavepoint, "": if app.Spec.SavepointInfo.SavepointLocation != "" { // we've already created the savepoint, now just waiting for the job to be cancelled return applicationUnchanged, nil @@ -680,7 +680,7 @@ func (s *FlinkStateMachine) handleApplicationDeleting(ctx context.Context, app * return applicationUnchanged, nil } -func (s *FlinkStateMachine) compareAndUpdateError(application *v1alpha1.FlinkApplication, err error) bool { +func (s *FlinkStateMachine) compareAndUpdateError(application *v1beta1.FlinkApplication, err error) bool { oldErr := application.Status.LastSeenError if err == nil && oldErr == nil { diff --git a/pkg/controller/flinkapplication/flink_state_machine_test.go b/pkg/controller/flinkapplication/flink_state_machine_test.go index 3d217f51..929383dc 100644 --- a/pkg/controller/flinkapplication/flink_state_machine_test.go +++ b/pkg/controller/flinkapplication/flink_state_machine_test.go @@ -11,7 +11,7 @@ import ( v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "github.com/lyft/flinkk8soperator/pkg/apis/app/v1alpha1" + "github.com/lyft/flinkk8soperator/pkg/apis/app/v1beta1" "github.com/lyft/flinkk8soperator/pkg/controller/common" "github.com/lyft/flinkk8soperator/pkg/controller/flink/mock" k8mock "github.com/lyft/flinkk8soperator/pkg/controller/k8/mock" @@ -37,7 +37,7 @@ func getTestStateMachine() FlinkStateMachine { } } -func testFlinkDeployment(app *v1alpha1.FlinkApplication) common.FlinkDeployment { +func testFlinkDeployment(app *v1beta1.FlinkApplication) common.FlinkDeployment { hash := flink.HashForApplication(app) return common.FlinkDeployment{ Jobmanager: flink.FetchJobMangerDeploymentCreateObj(app, hash), @@ -51,13 +51,13 @@ func TestHandleNewOrCreate(t *testing.T) { mockK8Cluster := stateMachineForTest.k8Cluster.(*k8mock.K8Cluster) mockK8Cluster.UpdateK8ObjectFunc = func(ctx context.Context, object runtime.Object) error { - application := object.(*v1alpha1.FlinkApplication) - assert.Equal(t, v1alpha1.FlinkApplicationClusterStarting, application.Status.Phase) + application := object.(*v1beta1.FlinkApplication) + assert.Equal(t, v1beta1.FlinkApplicationClusterStarting, application.Status.Phase) return nil } - err := stateMachineForTest.Handle(context.Background(), &v1alpha1.FlinkApplication{ - Spec: v1alpha1.FlinkApplicationSpec{}, + err := stateMachineForTest.Handle(context.Background(), &v1beta1.FlinkApplication{ + Spec: v1beta1.FlinkApplicationSpec{}, }) assert.Nil(t, err) } @@ -65,7 +65,7 @@ func TestHandleNewOrCreate(t *testing.T) { func TestHandleStartingClusterStarting(t *testing.T) { stateMachineForTest := getTestStateMachine() mockFlinkController := stateMachineForTest.flinkController.(*mock.FlinkController) - mockFlinkController.IsClusterReadyFunc = func(ctx context.Context, application *v1alpha1.FlinkApplication) (bool, error) { + mockFlinkController.IsClusterReadyFunc = func(ctx context.Context, application *v1beta1.FlinkApplication) (bool, error) { return false, nil } @@ -73,9 +73,9 @@ func TestHandleStartingClusterStarting(t *testing.T) { mockK8Cluster.UpdateK8ObjectFunc = func(ctx context.Context, object runtime.Object) error { return nil } - err := stateMachineForTest.Handle(context.Background(), &v1alpha1.FlinkApplication{ - Status: v1alpha1.FlinkApplicationStatus{ - Phase: v1alpha1.FlinkApplicationClusterStarting, + err := stateMachineForTest.Handle(context.Background(), &v1beta1.FlinkApplication{ + Status: v1beta1.FlinkApplicationStatus{ + Phase: v1beta1.FlinkApplicationClusterStarting, }, }) assert.Nil(t, err) @@ -85,11 +85,11 @@ func TestHandleStartingDual(t *testing.T) { updateInvoked := false stateMachineForTest := getTestStateMachine() mockFlinkController := stateMachineForTest.flinkController.(*mock.FlinkController) - mockFlinkController.IsClusterReadyFunc = func(ctx context.Context, application *v1alpha1.FlinkApplication) (bool, error) { + mockFlinkController.IsClusterReadyFunc = func(ctx context.Context, application *v1beta1.FlinkApplication) (bool, error) { return true, nil } - mockFlinkController.GetCurrentDeploymentsForAppFunc = func(ctx context.Context, application *v1alpha1.FlinkApplication) (*common.FlinkDeployment, error) { + mockFlinkController.GetCurrentDeploymentsForAppFunc = func(ctx context.Context, application *v1beta1.FlinkApplication) (*common.FlinkDeployment, error) { fd := testFlinkDeployment(application) fd.Taskmanager.Status.AvailableReplicas = 2 fd.Jobmanager.Status.AvailableReplicas = 1 @@ -98,14 +98,14 @@ func TestHandleStartingDual(t *testing.T) { mockK8Cluster := stateMachineForTest.k8Cluster.(*k8mock.K8Cluster) mockK8Cluster.UpdateK8ObjectFunc = func(ctx context.Context, object runtime.Object) error { - application := object.(*v1alpha1.FlinkApplication) - assert.Equal(t, v1alpha1.FlinkApplicationSavepointing, application.Status.Phase) + application := object.(*v1beta1.FlinkApplication) + assert.Equal(t, v1beta1.FlinkApplicationSavepointing, application.Status.Phase) updateInvoked = true return nil } - err := stateMachineForTest.Handle(context.Background(), &v1alpha1.FlinkApplication{ - Status: v1alpha1.FlinkApplicationStatus{ - Phase: v1alpha1.FlinkApplicationClusterStarting, + err := stateMachineForTest.Handle(context.Background(), &v1beta1.FlinkApplication{ + Status: v1beta1.FlinkApplicationStatus{ + Phase: v1beta1.FlinkApplicationClusterStarting, }, }) assert.True(t, updateInvoked) @@ -118,7 +118,7 @@ func TestHandleApplicationSavepointingInitialDeploy(t *testing.T) { stateMachineForTest := getTestStateMachine() mockFlinkController := stateMachineForTest.flinkController.(*mock.FlinkController) - mockFlinkController.CancelWithSavepointFunc = func(ctx context.Context, application *v1alpha1.FlinkApplication, hash string) (s string, e error) { + mockFlinkController.CancelWithSavepointFunc = func(ctx context.Context, application *v1beta1.FlinkApplication, hash string) (s string, e error) { // should not be called assert.False(t, true) return "", nil @@ -126,15 +126,15 @@ func TestHandleApplicationSavepointingInitialDeploy(t *testing.T) { mockK8Cluster := stateMachineForTest.k8Cluster.(*k8mock.K8Cluster) mockK8Cluster.UpdateK8ObjectFunc = func(ctx context.Context, object runtime.Object) error { - application := object.(*v1alpha1.FlinkApplication) - assert.Equal(t, v1alpha1.FlinkApplicationSubmittingJob, application.Status.Phase) + application := object.(*v1beta1.FlinkApplication) + assert.Equal(t, v1beta1.FlinkApplicationSubmittingJob, application.Status.Phase) updateInvoked = true return nil } - err := stateMachineForTest.Handle(context.Background(), &v1alpha1.FlinkApplication{ - Status: v1alpha1.FlinkApplicationStatus{ - Phase: v1alpha1.FlinkApplicationSavepointing, + err := stateMachineForTest.Handle(context.Background(), &v1beta1.FlinkApplication{ + Status: v1beta1.FlinkApplicationStatus{ + Phase: v1beta1.FlinkApplicationSavepointing, }, }) assert.True(t, updateInvoked) @@ -142,9 +142,9 @@ func TestHandleApplicationSavepointingInitialDeploy(t *testing.T) { } func TestHandleApplicationSavepointingDual(t *testing.T) { - app := v1alpha1.FlinkApplication{ - Status: v1alpha1.FlinkApplicationStatus{ - Phase: v1alpha1.FlinkApplicationSavepointing, + app := v1beta1.FlinkApplication{ + Status: v1beta1.FlinkApplicationStatus{ + Phase: v1beta1.FlinkApplicationSavepointing, DeployHash: "old-hash", }, } @@ -153,14 +153,14 @@ func TestHandleApplicationSavepointingDual(t *testing.T) { stateMachineForTest := getTestStateMachine() mockFlinkController := stateMachineForTest.flinkController.(*mock.FlinkController) - mockFlinkController.CancelWithSavepointFunc = func(ctx context.Context, application *v1alpha1.FlinkApplication, hash string) (s string, e error) { + mockFlinkController.CancelWithSavepointFunc = func(ctx context.Context, application *v1beta1.FlinkApplication, hash string) (s string, e error) { assert.Equal(t, "old-hash", hash) cancelInvoked = true return "trigger", nil } - mockFlinkController.GetSavepointStatusFunc = func(ctx context.Context, application *v1alpha1.FlinkApplication, hash string) (*client.SavepointResponse, error) { + mockFlinkController.GetSavepointStatusFunc = func(ctx context.Context, application *v1beta1.FlinkApplication, hash string) (*client.SavepointResponse, error) { assert.Equal(t, "old-hash", hash) return &client.SavepointResponse{ SavepointStatus: client.SavepointStatusResponse{ @@ -175,12 +175,12 @@ func TestHandleApplicationSavepointingDual(t *testing.T) { mockK8Cluster := stateMachineForTest.k8Cluster.(*k8mock.K8Cluster) updateCount := 0 mockK8Cluster.UpdateK8ObjectFunc = func(ctx context.Context, object runtime.Object) error { - application := object.(*v1alpha1.FlinkApplication) + application := object.(*v1beta1.FlinkApplication) if updateCount == 0 { assert.Equal(t, "trigger", application.Spec.SavepointInfo.TriggerID) } else { assert.Equal(t, testSavepointLocation, application.Spec.SavepointInfo.SavepointLocation) - assert.Equal(t, v1alpha1.FlinkApplicationSubmittingJob, application.Status.Phase) + assert.Equal(t, v1beta1.FlinkApplicationSubmittingJob, application.Status.Phase) } updateCount++ @@ -202,7 +202,7 @@ func TestHandleApplicationSavepointingFailed(t *testing.T) { updateInvoked := false stateMachineForTest := getTestStateMachine() mockFlinkController := stateMachineForTest.flinkController.(*mock.FlinkController) - mockFlinkController.GetSavepointStatusFunc = func(ctx context.Context, application *v1alpha1.FlinkApplication, hash string) (*client.SavepointResponse, error) { + mockFlinkController.GetSavepointStatusFunc = func(ctx context.Context, application *v1beta1.FlinkApplication, hash string) (*client.SavepointResponse, error) { return &client.SavepointResponse{ SavepointStatus: client.SavepointStatusResponse{ Status: client.SavePointCompleted, @@ -210,14 +210,14 @@ func TestHandleApplicationSavepointingFailed(t *testing.T) { }, nil } - app := v1alpha1.FlinkApplication{ - Spec: v1alpha1.FlinkApplicationSpec{ - SavepointInfo: v1alpha1.SavepointInfo{ + app := v1beta1.FlinkApplication{ + Spec: v1beta1.FlinkApplicationSpec{ + SavepointInfo: v1beta1.SavepointInfo{ TriggerID: "trigger", }, }, - Status: v1alpha1.FlinkApplicationStatus{ - Phase: v1alpha1.FlinkApplicationSavepointing, + Status: v1beta1.FlinkApplicationStatus{ + Phase: v1beta1.FlinkApplicationSavepointing, DeployHash: "blah", }, } @@ -225,10 +225,10 @@ func TestHandleApplicationSavepointingFailed(t *testing.T) { mockK8Cluster := stateMachineForTest.k8Cluster.(*k8mock.K8Cluster) mockK8Cluster.UpdateK8ObjectFunc = func(ctx context.Context, object runtime.Object) error { - application := object.(*v1alpha1.FlinkApplication) + application := object.(*v1beta1.FlinkApplication) assert.Empty(t, application.Spec.SavepointInfo.SavepointLocation) assert.Equal(t, hash, application.Status.FailedDeployHash) - assert.Equal(t, v1alpha1.FlinkApplicationDeployFailed, application.Status.Phase) + assert.Equal(t, v1beta1.FlinkApplicationDeployFailed, application.Status.Phase) updateInvoked = true return nil } @@ -240,21 +240,21 @@ func TestHandleApplicationSavepointingFailed(t *testing.T) { func TestRestoreFromExternalizedCheckpoint(t *testing.T) { updateInvoked := false - app := v1alpha1.FlinkApplication{ - Spec: v1alpha1.FlinkApplicationSpec{ - SavepointInfo: v1alpha1.SavepointInfo{ + app := v1beta1.FlinkApplication{ + Spec: v1beta1.FlinkApplicationSpec{ + SavepointInfo: v1beta1.SavepointInfo{ TriggerID: "trigger", }, }, - Status: v1alpha1.FlinkApplicationStatus{ - Phase: v1alpha1.FlinkApplicationSavepointing, + Status: v1beta1.FlinkApplicationStatus{ + Phase: v1beta1.FlinkApplicationSavepointing, DeployHash: "blah", }, } stateMachineForTest := getTestStateMachine() mockFlinkController := stateMachineForTest.flinkController.(*mock.FlinkController) - mockFlinkController.GetSavepointStatusFunc = func(ctx context.Context, application *v1alpha1.FlinkApplication, hash string) (*client.SavepointResponse, error) { + mockFlinkController.GetSavepointStatusFunc = func(ctx context.Context, application *v1beta1.FlinkApplication, hash string) (*client.SavepointResponse, error) { return &client.SavepointResponse{ SavepointStatus: client.SavepointStatusResponse{ Status: client.SavePointCompleted, @@ -262,15 +262,15 @@ func TestRestoreFromExternalizedCheckpoint(t *testing.T) { }, nil } - mockFlinkController.FindExternalizedCheckpointFunc = func(ctx context.Context, application *v1alpha1.FlinkApplication, hash string) (string, error) { + mockFlinkController.FindExternalizedCheckpointFunc = func(ctx context.Context, application *v1beta1.FlinkApplication, hash string) (string, error) { return "/tmp/checkpoint", nil } mockK8Cluster := stateMachineForTest.k8Cluster.(*k8mock.K8Cluster) mockK8Cluster.UpdateK8ObjectFunc = func(ctx context.Context, object runtime.Object) error { - application := object.(*v1alpha1.FlinkApplication) + application := object.(*v1beta1.FlinkApplication) assert.Equal(t, "/tmp/checkpoint", application.Spec.SavepointInfo.SavepointLocation) - assert.Equal(t, v1alpha1.FlinkApplicationSubmittingJob, application.Status.Phase) + assert.Equal(t, v1beta1.FlinkApplicationSubmittingJob, application.Status.Phase) updateInvoked = true return nil } @@ -282,19 +282,19 @@ func TestRestoreFromExternalizedCheckpoint(t *testing.T) { func TestSubmittingToRunning(t *testing.T) { jobID := "j1" - app := v1alpha1.FlinkApplication{ + app := v1beta1.FlinkApplication{ ObjectMeta: metav1.ObjectMeta{ Name: "test-app", Namespace: "flink", }, - Spec: v1alpha1.FlinkApplicationSpec{ + Spec: v1beta1.FlinkApplicationSpec{ JarName: "job.jar", Parallelism: 5, EntryClass: "com.my.Class", ProgramArgs: "--test", }, - Status: v1alpha1.FlinkApplicationStatus{ - Phase: v1alpha1.FlinkApplicationSubmittingJob, + Status: v1beta1.FlinkApplicationStatus{ + Phase: v1beta1.FlinkApplicationSubmittingJob, DeployHash: "old-hash", }, } @@ -302,12 +302,12 @@ func TestSubmittingToRunning(t *testing.T) { stateMachineForTest := getTestStateMachine() mockFlinkController := stateMachineForTest.flinkController.(*mock.FlinkController) - mockFlinkController.IsServiceReadyFunc = func(ctx context.Context, application *v1alpha1.FlinkApplication, hash string) (bool, error) { + mockFlinkController.IsServiceReadyFunc = func(ctx context.Context, application *v1beta1.FlinkApplication, hash string) (bool, error) { return true, nil } getCount := 0 - mockFlinkController.GetJobsForApplicationFunc = func(ctx context.Context, application *v1alpha1.FlinkApplication, hash string) ([]client.FlinkJob, error) { + mockFlinkController.GetJobsForApplicationFunc = func(ctx context.Context, application *v1beta1.FlinkApplication, hash string) ([]client.FlinkJob, error) { assert.Equal(t, appHash, hash) var res []client.FlinkJob if getCount == 1 { @@ -322,7 +322,7 @@ func TestSubmittingToRunning(t *testing.T) { } startCount := 0 - mockFlinkController.StartFlinkJobFunc = func(ctx context.Context, application *v1alpha1.FlinkApplication, hash string, + mockFlinkController.StartFlinkJobFunc = func(ctx context.Context, application *v1beta1.FlinkApplication, hash string, jarName string, parallelism int32, entryClass string, programArgs string, allowNonRestoredState bool) (string, error) { assert.Equal(t, appHash, hash) @@ -369,17 +369,17 @@ func TestSubmittingToRunning(t *testing.T) { service := object.(*v1.Service) assert.Equal(t, appHash, service.Spec.Selector["flink-app-hash"]) } else if updateCount == 1 { - application := object.(*v1alpha1.FlinkApplication) + application := object.(*v1beta1.FlinkApplication) assert.Equal(t, jobFinalizer, application.Finalizers[0]) } else if updateCount == 2 { - application := object.(*v1alpha1.FlinkApplication) + application := object.(*v1beta1.FlinkApplication) assert.Equal(t, jobID, application.Status.JobStatus.JobID) assert.Equal(t, appHash, application.Status.DeployHash) assert.Equal(t, app.Spec.JarName, app.Status.JobStatus.JarName) assert.Equal(t, app.Spec.Parallelism, app.Status.JobStatus.Parallelism) assert.Equal(t, app.Spec.EntryClass, app.Status.JobStatus.EntryClass) assert.Equal(t, app.Spec.ProgramArgs, app.Status.JobStatus.ProgramArgs) - assert.Equal(t, v1alpha1.FlinkApplicationRunning, application.Status.Phase) + assert.Equal(t, v1beta1.FlinkApplicationRunning, application.Status.Phase) } updateCount++ @@ -399,22 +399,22 @@ func TestSubmittingToRunning(t *testing.T) { func TestHandleApplicationNotReady(t *testing.T) { stateMachineForTest := getTestStateMachine() mockFlinkController := stateMachineForTest.flinkController.(*mock.FlinkController) - mockFlinkController.IsServiceReadyFunc = func(ctx context.Context, application *v1alpha1.FlinkApplication, hash string) (bool, error) { + mockFlinkController.IsServiceReadyFunc = func(ctx context.Context, application *v1beta1.FlinkApplication, hash string) (bool, error) { return false, nil } - mockFlinkController.GetJobsForApplicationFunc = func(ctx context.Context, application *v1alpha1.FlinkApplication, hash string) ([]client.FlinkJob, error) { + mockFlinkController.GetJobsForApplicationFunc = func(ctx context.Context, application *v1beta1.FlinkApplication, hash string) ([]client.FlinkJob, error) { assert.False(t, true) return nil, nil } - mockFlinkController.StartFlinkJobFunc = func(ctx context.Context, application *v1alpha1.FlinkApplication, hash string, + mockFlinkController.StartFlinkJobFunc = func(ctx context.Context, application *v1beta1.FlinkApplication, hash string, jarName string, parallelism int32, entryClass string, programArgs string, allowNonRestoredState bool) (string, error) { assert.False(t, true) return "", nil } - app := v1alpha1.FlinkApplication{ - Status: v1alpha1.FlinkApplicationStatus{ - Phase: v1alpha1.FlinkApplicationSubmittingJob, + app := v1beta1.FlinkApplication{ + Status: v1beta1.FlinkApplicationStatus{ + Phase: v1beta1.FlinkApplicationSubmittingJob, }, } @@ -444,7 +444,7 @@ func TestHandleApplicationNotReady(t *testing.T) { func TestHandleApplicationRunning(t *testing.T) { stateMachineForTest := getTestStateMachine() mockFlinkController := stateMachineForTest.flinkController.(*mock.FlinkController) - mockFlinkController.GetCurrentDeploymentsForAppFunc = func(ctx context.Context, application *v1alpha1.FlinkApplication) (*common.FlinkDeployment, error) { + mockFlinkController.GetCurrentDeploymentsForAppFunc = func(ctx context.Context, application *v1beta1.FlinkApplication) (*common.FlinkDeployment, error) { fd := testFlinkDeployment(application) return &fd, nil } @@ -454,9 +454,9 @@ func TestHandleApplicationRunning(t *testing.T) { assert.True(t, false) return nil } - err := stateMachineForTest.Handle(context.Background(), &v1alpha1.FlinkApplication{ - Status: v1alpha1.FlinkApplicationStatus{ - Phase: v1alpha1.FlinkApplicationRunning, + err := stateMachineForTest.Handle(context.Background(), &v1beta1.FlinkApplication{ + Status: v1beta1.FlinkApplicationStatus{ + Phase: v1beta1.FlinkApplicationRunning, }, }) assert.Nil(t, err) @@ -466,20 +466,20 @@ func TestRunningToClusterStarting(t *testing.T) { updateInvoked := false stateMachineForTest := getTestStateMachine() mockFlinkController := stateMachineForTest.flinkController.(*mock.FlinkController) - mockFlinkController.GetCurrentDeploymentsForAppFunc = func(ctx context.Context, application *v1alpha1.FlinkApplication) (*common.FlinkDeployment, error) { + mockFlinkController.GetCurrentDeploymentsForAppFunc = func(ctx context.Context, application *v1beta1.FlinkApplication) (*common.FlinkDeployment, error) { return nil, nil } mockK8Cluster := stateMachineForTest.k8Cluster.(*k8mock.K8Cluster) mockK8Cluster.UpdateK8ObjectFunc = func(ctx context.Context, object runtime.Object) error { - application := object.(*v1alpha1.FlinkApplication) - assert.Equal(t, v1alpha1.FlinkApplicationUpdating, application.Status.Phase) + application := object.(*v1beta1.FlinkApplication) + assert.Equal(t, v1beta1.FlinkApplicationUpdating, application.Status.Phase) updateInvoked = true return nil } - err := stateMachineForTest.Handle(context.Background(), &v1alpha1.FlinkApplication{ - Status: v1alpha1.FlinkApplicationStatus{ - Phase: v1alpha1.FlinkApplicationRunning, + err := stateMachineForTest.Handle(context.Background(), &v1beta1.FlinkApplication{ + Status: v1beta1.FlinkApplicationStatus{ + Phase: v1beta1.FlinkApplicationRunning, }, }) assert.True(t, updateInvoked) @@ -489,21 +489,21 @@ func TestRunningToClusterStarting(t *testing.T) { func TestRollingBack(t *testing.T) { jobID := "j1" - app := v1alpha1.FlinkApplication{ + app := v1beta1.FlinkApplication{ ObjectMeta: metav1.ObjectMeta{ Name: "test-app", Namespace: "flink", }, - Spec: v1alpha1.FlinkApplicationSpec{ + Spec: v1beta1.FlinkApplicationSpec{ JarName: "job.jar", Parallelism: 5, EntryClass: "com.my.Class", ProgramArgs: "--test", }, - Status: v1alpha1.FlinkApplicationStatus{ - Phase: v1alpha1.FlinkApplicationRollingBackJob, + Status: v1beta1.FlinkApplicationStatus{ + Phase: v1beta1.FlinkApplicationRollingBackJob, DeployHash: "old-hash", - JobStatus: v1alpha1.FlinkJobStatus{ + JobStatus: v1beta1.FlinkJobStatus{ JarName: "old-job.jar", Parallelism: 10, EntryClass: "com.my.OldClass", @@ -515,13 +515,13 @@ func TestRollingBack(t *testing.T) { stateMachineForTest := getTestStateMachine() mockFlinkController := stateMachineForTest.flinkController.(*mock.FlinkController) - mockFlinkController.IsServiceReadyFunc = func(ctx context.Context, application *v1alpha1.FlinkApplication, hash string) (bool, error) { + mockFlinkController.IsServiceReadyFunc = func(ctx context.Context, application *v1beta1.FlinkApplication, hash string) (bool, error) { assert.Equal(t, "old-hash", hash) return true, nil } startCalled := false - mockFlinkController.StartFlinkJobFunc = func(ctx context.Context, application *v1alpha1.FlinkApplication, hash string, + mockFlinkController.StartFlinkJobFunc = func(ctx context.Context, application *v1beta1.FlinkApplication, hash string, jarName string, parallelism int32, entryClass string, programArgs string, allowNonRestoredState bool) (string, error) { startCalled = true @@ -535,7 +535,7 @@ func TestRollingBack(t *testing.T) { } getCount := 0 - mockFlinkController.GetJobsForApplicationFunc = func(ctx context.Context, application *v1alpha1.FlinkApplication, hash string) ([]client.FlinkJob, error) { + mockFlinkController.GetJobsForApplicationFunc = func(ctx context.Context, application *v1beta1.FlinkApplication, hash string) ([]client.FlinkJob, error) { assert.Equal(t, "old-hash", hash) var res []client.FlinkJob if getCount == 1 { @@ -582,12 +582,12 @@ func TestRollingBack(t *testing.T) { service := object.(*v1.Service) assert.Equal(t, "old-hash", service.Spec.Selector["flink-app-hash"]) } else if updateCount == 1 { - application := object.(*v1alpha1.FlinkApplication) + application := object.(*v1beta1.FlinkApplication) assert.Equal(t, jobFinalizer, application.Finalizers[0]) } else if updateCount == 2 { - application := object.(*v1alpha1.FlinkApplication) + application := object.(*v1beta1.FlinkApplication) assert.Equal(t, appHash, application.Status.FailedDeployHash) - assert.Equal(t, v1alpha1.FlinkApplicationDeployFailed, application.Status.Phase) + assert.Equal(t, v1beta1.FlinkApplicationDeployFailed, application.Status.Phase) } updateCount++ @@ -609,9 +609,9 @@ func TestIsApplicationStuck(t *testing.T) { retryableErr := client.GetRetryableError(errors.New("blah"), "GetClusterOverview", "FAILED", 3) failFastError := client.GetNonRetryableError(errors.New("blah"), "SubmitJob", "400BadRequest") - app := &v1alpha1.FlinkApplication{ - Status: v1alpha1.FlinkApplicationStatus{ - Phase: v1alpha1.FlinkApplicationClusterStarting, + app := &v1beta1.FlinkApplication{ + Status: v1beta1.FlinkApplicationStatus{ + Phase: v1beta1.FlinkApplicationClusterStarting, DeployHash: "prevhash", LastSeenError: retryableErr.(*client.FlinkApplicationError), }, @@ -661,15 +661,15 @@ func TestDeleteWithSavepoint(t *testing.T) { stateMachineForTest := getTestStateMachine() jobID := "j1" - app := v1alpha1.FlinkApplication{ + app := v1beta1.FlinkApplication{ ObjectMeta: metav1.ObjectMeta{ Finalizers: []string{jobFinalizer}, DeletionTimestamp: &metav1.Time{Time: time.Now()}, }, - Status: v1alpha1.FlinkApplicationStatus{ - Phase: v1alpha1.FlinkApplicationDeleting, + Status: v1beta1.FlinkApplicationStatus{ + Phase: v1beta1.FlinkApplicationDeleting, DeployHash: "deployhash", - JobStatus: v1alpha1.FlinkJobStatus{ + JobStatus: v1beta1.FlinkJobStatus{ JobID: jobID, }, }, @@ -679,11 +679,11 @@ func TestDeleteWithSavepoint(t *testing.T) { savepointPath := "s3:///path/to/savepoint" mockFlinkController := stateMachineForTest.flinkController.(*mock.FlinkController) - mockFlinkController.CancelWithSavepointFunc = func(ctx context.Context, application *v1alpha1.FlinkApplication, hash string) (string, error) { + mockFlinkController.CancelWithSavepointFunc = func(ctx context.Context, application *v1beta1.FlinkApplication, hash string) (string, error) { return triggerID, nil } - mockFlinkController.GetJobsForApplicationFunc = func(ctx context.Context, application *v1alpha1.FlinkApplication, hash string) (jobs []client.FlinkJob, err error) { + mockFlinkController.GetJobsForApplicationFunc = func(ctx context.Context, application *v1beta1.FlinkApplication, hash string) (jobs []client.FlinkJob, err error) { return []client.FlinkJob{ { JobID: jobID, @@ -695,8 +695,8 @@ func TestDeleteWithSavepoint(t *testing.T) { mockK8Cluster := stateMachineForTest.k8Cluster.(*k8mock.K8Cluster) updateCount := 1 mockK8Cluster.UpdateK8ObjectFunc = func(ctx context.Context, object runtime.Object) error { - application := object.(*v1alpha1.FlinkApplication) - assert.Equal(t, v1alpha1.FlinkApplicationDeleting, application.Status.Phase) + application := object.(*v1beta1.FlinkApplication) + assert.Equal(t, v1beta1.FlinkApplicationDeleting, application.Status.Phase) if updateCount == 1 { assert.Equal(t, triggerID, application.Spec.SavepointInfo.TriggerID) @@ -714,7 +714,7 @@ func TestDeleteWithSavepoint(t *testing.T) { assert.NoError(t, err) assert.Equal(t, 2, updateCount) - mockFlinkController.GetSavepointStatusFunc = func(ctx context.Context, application *v1alpha1.FlinkApplication, hash string) (*client.SavepointResponse, error) { + mockFlinkController.GetSavepointStatusFunc = func(ctx context.Context, application *v1beta1.FlinkApplication, hash string) (*client.SavepointResponse, error) { return &client.SavepointResponse{ SavepointStatus: client.SavepointStatusResponse{ Status: client.SavePointCompleted, @@ -730,7 +730,7 @@ func TestDeleteWithSavepoint(t *testing.T) { assert.Equal(t, 3, updateCount) - mockFlinkController.GetJobsForApplicationFunc = func(ctx context.Context, application *v1alpha1.FlinkApplication, hash string) (jobs []client.FlinkJob, err error) { + mockFlinkController.GetJobsForApplicationFunc = func(ctx context.Context, application *v1beta1.FlinkApplication, hash string) (jobs []client.FlinkJob, err error) { return []client.FlinkJob{ { JobID: jobID, @@ -750,15 +750,15 @@ func TestDeleteWithSavepointAndFinishedJob(t *testing.T) { stateMachineForTest := getTestStateMachine() jobID := "j1" - app := v1alpha1.FlinkApplication{ + app := v1beta1.FlinkApplication{ ObjectMeta: metav1.ObjectMeta{ Finalizers: []string{jobFinalizer}, DeletionTimestamp: &metav1.Time{Time: time.Now()}, }, - Status: v1alpha1.FlinkApplicationStatus{ - Phase: v1alpha1.FlinkApplicationDeleting, + Status: v1beta1.FlinkApplicationStatus{ + Phase: v1beta1.FlinkApplicationDeleting, DeployHash: "deployhash", - JobStatus: v1alpha1.FlinkJobStatus{ + JobStatus: v1beta1.FlinkJobStatus{ JobID: jobID, }, }, @@ -766,7 +766,7 @@ func TestDeleteWithSavepointAndFinishedJob(t *testing.T) { mockFlinkController := stateMachineForTest.flinkController.(*mock.FlinkController) - mockFlinkController.GetJobsForApplicationFunc = func(ctx context.Context, application *v1alpha1.FlinkApplication, hash string) (jobs []client.FlinkJob, err error) { + mockFlinkController.GetJobsForApplicationFunc = func(ctx context.Context, application *v1beta1.FlinkApplication, hash string) (jobs []client.FlinkJob, err error) { return []client.FlinkJob{ { JobID: jobID, @@ -778,8 +778,8 @@ func TestDeleteWithSavepointAndFinishedJob(t *testing.T) { mockK8Cluster := stateMachineForTest.k8Cluster.(*k8mock.K8Cluster) mockK8Cluster.UpdateK8ObjectFunc = func(ctx context.Context, object runtime.Object) error { - application := object.(*v1alpha1.FlinkApplication) - assert.Equal(t, v1alpha1.FlinkApplicationDeleting, application.Status.Phase) + application := object.(*v1beta1.FlinkApplication) + assert.Equal(t, v1beta1.FlinkApplicationDeleting, application.Status.Phase) assert.Equal(t, 0, len(app.Finalizers)) @@ -795,17 +795,17 @@ func TestDeleteWithForceCancel(t *testing.T) { jobID := "j1" - app := v1alpha1.FlinkApplication{ + app := v1beta1.FlinkApplication{ ObjectMeta: metav1.ObjectMeta{ Finalizers: []string{jobFinalizer}, DeletionTimestamp: &metav1.Time{Time: time.Now()}, }, - Spec: v1alpha1.FlinkApplicationSpec{ - DeleteMode: v1alpha1.DeleteModeForceCancel, + Spec: v1beta1.FlinkApplicationSpec{ + DeleteMode: v1beta1.DeleteModeForceCancel, }, - Status: v1alpha1.FlinkApplicationStatus{ - Phase: v1alpha1.FlinkApplicationDeleting, - JobStatus: v1alpha1.FlinkJobStatus{ + Status: v1beta1.FlinkApplicationStatus{ + Phase: v1beta1.FlinkApplicationDeleting, + JobStatus: v1beta1.FlinkJobStatus{ JobID: jobID, }, DeployHash: "deployhash", @@ -814,7 +814,7 @@ func TestDeleteWithForceCancel(t *testing.T) { mockFlinkController := stateMachineForTest.flinkController.(*mock.FlinkController) - mockFlinkController.GetJobsForApplicationFunc = func(ctx context.Context, application *v1alpha1.FlinkApplication, hash string) (jobs []client.FlinkJob, err error) { + mockFlinkController.GetJobsForApplicationFunc = func(ctx context.Context, application *v1beta1.FlinkApplication, hash string) (jobs []client.FlinkJob, err error) { return []client.FlinkJob{ { JobID: jobID, @@ -824,7 +824,7 @@ func TestDeleteWithForceCancel(t *testing.T) { } cancelled := false - mockFlinkController.ForceCancelFunc = func(ctx context.Context, application *v1alpha1.FlinkApplication, hash string) error { + mockFlinkController.ForceCancelFunc = func(ctx context.Context, application *v1beta1.FlinkApplication, hash string) error { cancelled = true return nil } @@ -832,8 +832,8 @@ func TestDeleteWithForceCancel(t *testing.T) { mockK8Cluster := stateMachineForTest.k8Cluster.(*k8mock.K8Cluster) updateCount := 1 mockK8Cluster.UpdateK8ObjectFunc = func(ctx context.Context, object runtime.Object) error { - application := object.(*v1alpha1.FlinkApplication) - assert.Equal(t, v1alpha1.FlinkApplicationDeleting, application.Status.Phase) + application := object.(*v1beta1.FlinkApplication) + assert.Equal(t, v1beta1.FlinkApplicationDeleting, application.Status.Phase) if updateCount == 1 { assert.Equal(t, 0, len(app.Finalizers)) @@ -848,7 +848,7 @@ func TestDeleteWithForceCancel(t *testing.T) { assert.Equal(t, 1, updateCount) assert.True(t, cancelled) - mockFlinkController.GetJobsForApplicationFunc = func(ctx context.Context, application *v1alpha1.FlinkApplication, hash string) (jobs []client.FlinkJob, err error) { + mockFlinkController.GetJobsForApplicationFunc = func(ctx context.Context, application *v1beta1.FlinkApplication, hash string) (jobs []client.FlinkJob, err error) { return []client.FlinkJob{ { JobID: jobID, @@ -865,16 +865,16 @@ func TestDeleteWithForceCancel(t *testing.T) { func TestDeleteModeNone(t *testing.T) { stateMachineForTest := getTestStateMachine() - app := v1alpha1.FlinkApplication{ + app := v1beta1.FlinkApplication{ ObjectMeta: metav1.ObjectMeta{ Finalizers: []string{jobFinalizer}, DeletionTimestamp: &metav1.Time{Time: time.Now()}, }, - Spec: v1alpha1.FlinkApplicationSpec{ - DeleteMode: v1alpha1.DeleteModeNone, + Spec: v1beta1.FlinkApplicationSpec{ + DeleteMode: v1beta1.DeleteModeNone, }, - Status: v1alpha1.FlinkApplicationStatus{ - Phase: v1alpha1.FlinkApplicationDeleting, + Status: v1beta1.FlinkApplicationStatus{ + Phase: v1beta1.FlinkApplicationDeleting, }, } @@ -882,7 +882,7 @@ func TestDeleteModeNone(t *testing.T) { mockFlinkController := stateMachineForTest.flinkController.(*mock.FlinkController) - mockFlinkController.GetJobsForApplicationFunc = func(ctx context.Context, application *v1alpha1.FlinkApplication, hash string) (jobs []client.FlinkJob, err error) { + mockFlinkController.GetJobsForApplicationFunc = func(ctx context.Context, application *v1beta1.FlinkApplication, hash string) (jobs []client.FlinkJob, err error) { return []client.FlinkJob{ { JobID: jobID, @@ -892,7 +892,7 @@ func TestDeleteModeNone(t *testing.T) { } cancelled := false - mockFlinkController.ForceCancelFunc = func(ctx context.Context, application *v1alpha1.FlinkApplication, hash string) error { + mockFlinkController.ForceCancelFunc = func(ctx context.Context, application *v1beta1.FlinkApplication, hash string) error { cancelled = true return nil } @@ -900,8 +900,8 @@ func TestDeleteModeNone(t *testing.T) { mockK8Cluster := stateMachineForTest.k8Cluster.(*k8mock.K8Cluster) updateCount := 1 mockK8Cluster.UpdateK8ObjectFunc = func(ctx context.Context, object runtime.Object) error { - application := object.(*v1alpha1.FlinkApplication) - assert.Equal(t, v1alpha1.FlinkApplicationDeleting, application.Status.Phase) + application := object.(*v1beta1.FlinkApplication) + assert.Equal(t, v1beta1.FlinkApplicationDeleting, application.Status.Phase) if updateCount == 1 { assert.Equal(t, 0, len(app.Finalizers)) @@ -920,9 +920,9 @@ func TestDeleteModeNone(t *testing.T) { func TestHandleInvalidPhase(t *testing.T) { stateMachineForTest := getTestStateMachine() - err := stateMachineForTest.Handle(context.Background(), &v1alpha1.FlinkApplication{ - Spec: v1alpha1.FlinkApplicationSpec{}, - Status: v1alpha1.FlinkApplicationStatus{ + err := stateMachineForTest.Handle(context.Background(), &v1beta1.FlinkApplication{ + Spec: v1beta1.FlinkApplicationSpec{}, + Status: v1beta1.FlinkApplicationStatus{ Phase: "asd", }, }) @@ -931,19 +931,19 @@ func TestHandleInvalidPhase(t *testing.T) { } func TestRollbackWithRetryableError(t *testing.T) { - app := v1alpha1.FlinkApplication{ + app := v1beta1.FlinkApplication{ ObjectMeta: metav1.ObjectMeta{ Name: "test-app", Namespace: "flink", }, - Spec: v1alpha1.FlinkApplicationSpec{ + Spec: v1beta1.FlinkApplicationSpec{ JarName: "job.jar", Parallelism: 5, EntryClass: "com.my.Class", ProgramArgs: "--test", }, - Status: v1alpha1.FlinkApplicationStatus{ - Phase: v1alpha1.FlinkApplicationSavepointing, + Status: v1beta1.FlinkApplicationStatus{ + Phase: v1beta1.FlinkApplicationSavepointing, DeployHash: "old-hash-retry", }, } @@ -951,7 +951,7 @@ func TestRollbackWithRetryableError(t *testing.T) { retryableErr := client.GetRetryableError(errors.New("blah"), "GetClusterOverview", "FAILED", 3) stateMachineForTest := getTestStateMachine() mockFlinkController := stateMachineForTest.flinkController.(*mock.FlinkController) - mockFlinkController.CancelWithSavepointFunc = func(ctx context.Context, app *v1alpha1.FlinkApplication, hash string) (savepoint string, err error) { + mockFlinkController.CancelWithSavepointFunc = func(ctx context.Context, app *v1beta1.FlinkApplication, hash string) (savepoint string, err error) { return "", retryableErr } @@ -985,8 +985,8 @@ func TestRollbackWithRetryableError(t *testing.T) { } retries := 0 - for ; app.Status.Phase != v1alpha1.FlinkApplicationDeployFailed; retries++ { - assert.Equal(t, v1alpha1.FlinkApplicationSavepointing, app.Status.Phase) + for ; app.Status.Phase != v1beta1.FlinkApplicationDeployFailed; retries++ { + assert.Equal(t, v1beta1.FlinkApplicationSavepointing, app.Status.Phase) err := stateMachineForTest.Handle(context.Background(), &app) // First attempt does not rollback @@ -1000,25 +1000,25 @@ func TestRollbackWithRetryableError(t *testing.T) { assert.Equal(t, 5, retries) assert.Equal(t, 5, updateErrCount) // Retries should have been exhausted and errors and retry counts reset - assert.Equal(t, v1alpha1.FlinkApplicationDeployFailed, app.Status.Phase) + assert.Equal(t, v1beta1.FlinkApplicationDeployFailed, app.Status.Phase) assert.Equal(t, int32(0), app.Status.RetryCount) assert.Nil(t, app.Status.LastSeenError) } func TestRollbackWithFailFastError(t *testing.T) { - app := v1alpha1.FlinkApplication{ + app := v1beta1.FlinkApplication{ ObjectMeta: metav1.ObjectMeta{ Name: "test-app", Namespace: "flink", }, - Spec: v1alpha1.FlinkApplicationSpec{ + Spec: v1beta1.FlinkApplicationSpec{ JarName: "job.jar", Parallelism: 5, EntryClass: "com.my.Class", ProgramArgs: "--test", }, - Status: v1alpha1.FlinkApplicationStatus{ - Phase: v1alpha1.FlinkApplicationSubmittingJob, + Status: v1beta1.FlinkApplicationStatus{ + Phase: v1beta1.FlinkApplicationSubmittingJob, DeployHash: "old-hash-retry-err", }, } @@ -1027,7 +1027,7 @@ func TestRollbackWithFailFastError(t *testing.T) { mockFlinkController := stateMachineForTest.flinkController.(*mock.FlinkController) getCount := 0 - mockFlinkController.GetJobsForApplicationFunc = func(ctx context.Context, application *v1alpha1.FlinkApplication, hash string) ([]client.FlinkJob, error) { + mockFlinkController.GetJobsForApplicationFunc = func(ctx context.Context, application *v1beta1.FlinkApplication, hash string) ([]client.FlinkJob, error) { var res []client.FlinkJob if getCount == 1 { res = []client.FlinkJob{ @@ -1040,11 +1040,11 @@ func TestRollbackWithFailFastError(t *testing.T) { return res, nil } - mockFlinkController.IsServiceReadyFunc = func(ctx context.Context, application *v1alpha1.FlinkApplication, hash string) (bool, error) { + mockFlinkController.IsServiceReadyFunc = func(ctx context.Context, application *v1beta1.FlinkApplication, hash string) (bool, error) { return true, nil } failFastError := client.GetNonRetryableError(errors.New("blah"), "SubmitJob", "400BadRequest") - mockFlinkController.StartFlinkJobFunc = func(ctx context.Context, application *v1alpha1.FlinkApplication, hash string, + mockFlinkController.StartFlinkJobFunc = func(ctx context.Context, application *v1beta1.FlinkApplication, hash string, jarName string, parallelism int32, entryClass string, programArgs string, allowNonRestoredState bool) (string, error) { return "", failFastError } @@ -1079,9 +1079,9 @@ func TestRollbackWithFailFastError(t *testing.T) { } retries := 0 var err error - for ; app.Status.Phase == v1alpha1.FlinkApplicationSubmittingJob; retries++ { + for ; app.Status.Phase == v1beta1.FlinkApplicationSubmittingJob; retries++ { err = stateMachineForTest.Handle(context.Background(), &app) - if app.Status.Phase == v1alpha1.FlinkApplicationSubmittingJob { + if app.Status.Phase == v1beta1.FlinkApplicationSubmittingJob { assert.NotNil(t, err) assert.Equal(t, int32(0), app.Status.RetryCount) assert.NotNil(t, app.Status.LastSeenError) @@ -1091,25 +1091,25 @@ func TestRollbackWithFailFastError(t *testing.T) { assert.Equal(t, 2, retries) // once in rollingback phase, errors no longer exist - assert.Equal(t, v1alpha1.FlinkApplicationRollingBackJob, app.Status.Phase) + assert.Equal(t, v1beta1.FlinkApplicationRollingBackJob, app.Status.Phase) assert.Equal(t, int32(0), app.Status.RetryCount) assert.Nil(t, app.Status.LastSeenError) } func TestErrorHandlingInRunningPhase(t *testing.T) { - app := v1alpha1.FlinkApplication{ + app := v1beta1.FlinkApplication{ ObjectMeta: metav1.ObjectMeta{ Name: "test-app", Namespace: "flink", }, - Spec: v1alpha1.FlinkApplicationSpec{ + Spec: v1beta1.FlinkApplicationSpec{ JarName: "job.jar", Parallelism: 5, EntryClass: "com.my.Class", ProgramArgs: "--test", }, - Status: v1alpha1.FlinkApplicationStatus{ - Phase: v1alpha1.FlinkApplicationRunning, + Status: v1beta1.FlinkApplicationStatus{ + Phase: v1beta1.FlinkApplicationRunning, DeployHash: "old-hash-retry-err", }, } @@ -1117,7 +1117,7 @@ func TestErrorHandlingInRunningPhase(t *testing.T) { stateMachineForTest := getTestStateMachine() mockFlinkController := stateMachineForTest.flinkController.(*mock.FlinkController) - mockFlinkController.GetJobsForApplicationFunc = func(ctx context.Context, application *v1alpha1.FlinkApplication, hash string) ([]client.FlinkJob, error) { + mockFlinkController.GetJobsForApplicationFunc = func(ctx context.Context, application *v1beta1.FlinkApplication, hash string) ([]client.FlinkJob, error) { return nil, client.GetNonRetryableError(errors.New("running phase error"), "TestError", "400") } @@ -1131,20 +1131,20 @@ func TestErrorHandlingInRunningPhase(t *testing.T) { func TestForceRollback(t *testing.T) { oldHash := "old-hash-force-rollback" - app := v1alpha1.FlinkApplication{ + app := v1beta1.FlinkApplication{ ObjectMeta: metav1.ObjectMeta{ Name: "test-app", Namespace: "flink", }, - Spec: v1alpha1.FlinkApplicationSpec{ + Spec: v1beta1.FlinkApplicationSpec{ JarName: "job.jar", Parallelism: 5, EntryClass: "com.my.Class", ProgramArgs: "--test", ForceRollback: true, }, - Status: v1alpha1.FlinkApplicationStatus{ - Phase: v1alpha1.FlinkApplicationSubmittingJob, + Status: v1beta1.FlinkApplicationStatus{ + Phase: v1beta1.FlinkApplicationSubmittingJob, DeployHash: oldHash, }, } @@ -1181,14 +1181,14 @@ func TestForceRollback(t *testing.T) { } mockFlinkController := stateMachineForTest.flinkController.(*mock.FlinkController) - mockFlinkController.IsServiceReadyFunc = func(ctx context.Context, application *v1alpha1.FlinkApplication, hash string) (bool, error) { + mockFlinkController.IsServiceReadyFunc = func(ctx context.Context, application *v1beta1.FlinkApplication, hash string) (bool, error) { return true, nil } err := stateMachineForTest.Handle(context.Background(), &app) assert.Nil(t, err) // rolled deploy while cluster is starting - assert.Equal(t, v1alpha1.FlinkApplicationRollingBackJob, app.Status.Phase) + assert.Equal(t, v1beta1.FlinkApplicationRollingBackJob, app.Status.Phase) assert.True(t, app.Spec.ForceRollback) err = stateMachineForTest.Handle(context.Background(), &app) @@ -1200,19 +1200,19 @@ func TestForceRollback(t *testing.T) { func TestLastSeenErrTimeIsNil(t *testing.T) { oldHash := "old-hash-force-nil" retryableErr := client.GetRetryableError(errors.New("blah"), "GetClusterOverview", "FAILED", 3) - app := v1alpha1.FlinkApplication{ + app := v1beta1.FlinkApplication{ ObjectMeta: metav1.ObjectMeta{ Name: "test-app", Namespace: "flink", }, - Spec: v1alpha1.FlinkApplicationSpec{ + Spec: v1beta1.FlinkApplicationSpec{ JarName: "job.jar", Parallelism: 5, EntryClass: "com.my.Class", ProgramArgs: "--test", }, - Status: v1alpha1.FlinkApplicationStatus{ - Phase: v1alpha1.FlinkApplicationClusterStarting, + Status: v1beta1.FlinkApplicationStatus{ + Phase: v1beta1.FlinkApplicationClusterStarting, DeployHash: oldHash, LastSeenError: retryableErr.(*client.FlinkApplicationError), }, diff --git a/tmp/codegen/update-generated.sh b/tmp/codegen/update-generated.sh index eaa93acc..1bbdf169 100755 --- a/tmp/codegen/update-generated.sh +++ b/tmp/codegen/update-generated.sh @@ -8,5 +8,5 @@ vendor/k8s.io/code-generator/generate-groups.sh \ deepcopy,client \ github.com/lyft/flinkk8soperator/pkg/client \ github.com/lyft/flinkk8soperator/pkg/apis \ -app:v1alpha1 \ +app:v1beta1 \ --go-header-file "./tmp/codegen/boilerplate.go.txt" diff --git a/version/version.go b/version/version.go index e3e130bf..dd10d2c9 100644 --- a/version/version.go +++ b/version/version.go @@ -1,5 +1,5 @@ package version var ( - Version = "0.0.1" + Version = "0.2.0" )