Skip to content

Commit b03da56

Browse files
authored
Embed struct, not pointer in resources (#2829)
## Changes - Embed struct by value not by pointer in all the resources. - Remove IsNil method from the resource interface and implementations (it's never true). ## Why - Prevents a class of crashes related to nil pointer, like #2776 and #1937 - Simplify user code, no need to check nilness as much. ## Tests Existing tests.
1 parent 52c2f92 commit b03da56

File tree

91 files changed

+331
-443
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+331
-443
lines changed

bundle/apps/interpolate_variables_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func TestAppInterpolateVariables(t *testing.T) {
1717
Resources: config.Resources{
1818
Apps: map[string]*resources.App{
1919
"my_app_1": {
20-
App: &apps.App{
20+
App: apps.App{
2121
Name: "my_app_1",
2222
},
2323
Config: map[string]any{
@@ -28,7 +28,7 @@ func TestAppInterpolateVariables(t *testing.T) {
2828
},
2929
},
3030
"my_app_2": {
31-
App: &apps.App{
31+
App: apps.App{
3232
Name: "my_app_2",
3333
},
3434
},

bundle/apps/upload_config_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func TestAppUploadConfig(t *testing.T) {
3737
Resources: config.Resources{
3838
Apps: map[string]*resources.App{
3939
"my_app": {
40-
App: &apps.App{
40+
App: apps.App{
4141
Name: "my_app",
4242
},
4343
SourceCodePath: "./my_app",

bundle/apps/validate_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ func TestAppsValidateSameSourcePath(t *testing.T) {
3232
Resources: config.Resources{
3333
Apps: map[string]*resources.App{
3434
"app1": {
35-
App: &apps.App{
35+
App: apps.App{
3636
Name: "app1",
3737
},
3838
SourceCodePath: "./app1",
3939
},
4040
"app2": {
41-
App: &apps.App{
41+
App: apps.App{
4242
Name: "app2",
4343
},
4444
SourceCodePath: "./app1",

bundle/config/mutator/initialize_urls_test.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,69 +26,69 @@ func TestInitializeURLs(t *testing.T) {
2626
Jobs: map[string]*resources.Job{
2727
"job1": {
2828
ID: "1",
29-
JobSettings: &jobs.JobSettings{Name: "job1"},
29+
JobSettings: jobs.JobSettings{Name: "job1"},
3030
},
3131
},
3232
Pipelines: map[string]*resources.Pipeline{
3333
"pipeline1": {
3434
ID: "3",
35-
CreatePipeline: &pipelines.CreatePipeline{Name: "pipeline1"},
35+
CreatePipeline: pipelines.CreatePipeline{Name: "pipeline1"},
3636
},
3737
},
3838
Experiments: map[string]*resources.MlflowExperiment{
3939
"experiment1": {
4040
ID: "4",
41-
Experiment: &ml.Experiment{Name: "experiment1"},
41+
Experiment: ml.Experiment{Name: "experiment1"},
4242
},
4343
},
4444
Models: map[string]*resources.MlflowModel{
4545
"model1": {
4646
ID: "a model uses its name for identifier",
47-
Model: &ml.Model{Name: "a model uses its name for identifier"},
47+
Model: ml.Model{Name: "a model uses its name for identifier"},
4848
},
4949
},
5050
ModelServingEndpoints: map[string]*resources.ModelServingEndpoint{
5151
"servingendpoint1": {
5252
ID: "my_serving_endpoint",
53-
CreateServingEndpoint: &serving.CreateServingEndpoint{
53+
CreateServingEndpoint: serving.CreateServingEndpoint{
5454
Name: "my_serving_endpoint",
5555
},
5656
},
5757
},
5858
RegisteredModels: map[string]*resources.RegisteredModel{
5959
"registeredmodel1": {
6060
ID: "8",
61-
CreateRegisteredModelRequest: &catalog.CreateRegisteredModelRequest{
61+
CreateRegisteredModelRequest: catalog.CreateRegisteredModelRequest{
6262
Name: "my_registered_model",
6363
},
6464
},
6565
},
6666
QualityMonitors: map[string]*resources.QualityMonitor{
6767
"qualityMonitor1": {
6868
TableName: "catalog.schema.qualityMonitor1",
69-
CreateMonitor: &catalog.CreateMonitor{},
69+
CreateMonitor: catalog.CreateMonitor{},
7070
},
7171
},
7272
Schemas: map[string]*resources.Schema{
7373
"schema1": {
7474
ID: "catalog.schema",
75-
CreateSchema: &catalog.CreateSchema{
75+
CreateSchema: catalog.CreateSchema{
7676
Name: "schema",
7777
},
7878
},
7979
},
8080
Clusters: map[string]*resources.Cluster{
8181
"cluster1": {
8282
ID: "1017-103929-vlr7jzcf",
83-
ClusterSpec: &compute.ClusterSpec{
83+
ClusterSpec: compute.ClusterSpec{
8484
ClusterName: "cluster1",
8585
},
8686
},
8787
},
8888
Dashboards: map[string]*resources.Dashboard{
8989
"dashboard1": {
9090
ID: "01ef8d56871e1d50ae30ce7375e42478",
91-
Dashboard: &dashboards.Dashboard{
91+
Dashboard: dashboards.Dashboard{
9292
DisplayName: "My special dashboard",
9393
},
9494
},
@@ -127,7 +127,7 @@ func TestInitializeURLsWithoutOrgId(t *testing.T) {
127127
Jobs: map[string]*resources.Job{
128128
"job1": {
129129
ID: "1",
130-
JobSettings: &jobs.JobSettings{Name: "job1"},
130+
JobSettings: jobs.JobSettings{Name: "job1"},
131131
},
132132
},
133133
},

bundle/config/mutator/normalize_paths.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func collectGitSourcePaths(b *bundle.Bundle) []dyn.Path {
7272
var jobs []dyn.Path
7373

7474
for name, job := range b.Config.Resources.Jobs {
75-
if job == nil || job.JobSettings == nil {
75+
if job == nil {
7676
continue
7777
}
7878
if job.GitSource != nil {

bundle/config/mutator/normalize_paths_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func TestNormalizePaths(t *testing.T) {
2222
Config: config.Root{
2323
Resources: config.Resources{
2424
Jobs: map[string]*resources.Job{
25-
"job1": {JobSettings: &jobs.JobSettings{
25+
"job1": {JobSettings: jobs.JobSettings{
2626
Tasks: []jobs.Task{
2727
{
2828
NotebookTask: &jobs.NotebookTask{

bundle/config/mutator/paths/job_paths_visitor_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func TestVisitJobPaths(t *testing.T) {
5151
}
5252

5353
job0 := &resources.Job{
54-
JobSettings: &jobs.JobSettings{
54+
JobSettings: jobs.JobSettings{
5555
Tasks: []jobs.Task{
5656
task0,
5757
task1,
@@ -96,7 +96,7 @@ func TestVisitJobPaths_environments(t *testing.T) {
9696
},
9797
}
9898
job0 := &resources.Job{
99-
JobSettings: &jobs.JobSettings{
99+
JobSettings: jobs.JobSettings{
100100
Environments: []jobs.JobEnvironment{
101101
environment0,
102102
},
@@ -131,7 +131,7 @@ func TestVisitJobPaths_foreach(t *testing.T) {
131131
},
132132
}
133133
job0 := &resources.Job{
134-
JobSettings: &jobs.JobSettings{
134+
JobSettings: jobs.JobSettings{
135135
Tasks: []jobs.Task{
136136
task0,
137137
},

bundle/config/mutator/paths/pipeline_paths_visitor_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ func TestVisitPipelinePaths(t *testing.T) {
1515
Resources: config.Resources{
1616
Pipelines: map[string]*resources.Pipeline{
1717
"pipeline0": {
18-
CreatePipeline: &pipelines.CreatePipeline{
18+
CreatePipeline: pipelines.CreatePipeline{
1919
Libraries: []pipelines.PipelineLibrary{
2020
{
2121
File: &pipelines.FileLibrary{

bundle/config/mutator/resolve_variable_references_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func TestResolveVariableReferencesWithSourceLinkedDeployment(t *testing.T) {
4848
Resources: config.Resources{
4949
Pipelines: map[string]*resources.Pipeline{
5050
"pipeline1": {
51-
CreatePipeline: &pipelines.CreatePipeline{
51+
CreatePipeline: pipelines.CreatePipeline{
5252
Configuration: map[string]string{
5353
"source": "${workspace.file_path}",
5454
},

bundle/config/mutator/resourcemutator/apply_bundle_permissions_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ func TestApplyBundlePermissions(t *testing.T) {
3030
Resources: config.Resources{
3131
Jobs: map[string]*resources.Job{
3232
"job_1": {
33-
JobSettings: &jobs.JobSettings{
33+
JobSettings: jobs.JobSettings{
3434
Name: "job_1",
3535
},
3636
},
3737
"job_2": {
38-
JobSettings: &jobs.JobSettings{
38+
JobSettings: jobs.JobSettings{
3939
Name: "job_2",
4040
},
4141
},
@@ -139,15 +139,15 @@ func TestWarningOnOverlapPermission(t *testing.T) {
139139
Resources: config.Resources{
140140
Jobs: map[string]*resources.Job{
141141
"job_1": {
142-
JobSettings: &jobs.JobSettings{
142+
JobSettings: jobs.JobSettings{
143143
Name: "job_1",
144144
},
145145
Permissions: []resources.JobPermission{
146146
{Level: "CAN_VIEW", UserName: "TestUser"},
147147
},
148148
},
149149
"job_2": {
150-
JobSettings: &jobs.JobSettings{
150+
JobSettings: jobs.JobSettings{
151151
Name: "job_2",
152152
},
153153
Permissions: []resources.JobPermission{

0 commit comments

Comments
 (0)