Skip to content

Commit

Permalink
Add rerun permissions specification to job config
Browse files Browse the repository at this point in the history
  • Loading branch information
mirandachrist committed Jul 18, 2019
1 parent 1183c9d commit b86afbd
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 1 deletion.
12 changes: 12 additions & 0 deletions prow/apis/prowjobs/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,18 @@ type ProwJobSpec struct {

// ReporterConfig holds reporter-specific configuration
ReporterConfig *ReporterConfig `json:"reporter_config,omitempty"`

// RerunPermissions holds information about which users can rerun the job
RerunPermissions *RerunPermissions `json:"rerun_permissions,omitempty"`
}

type RerunPermissions struct {
// If AllowAnyone is set to true, any user can rerun the job
AllowAnyone bool `json:"allow_anyone,omitempty"`
// GitHubTeams contains IDs of GitHub teams of users who can rerun the job
GitHubTeams []int `json:"github_teams,omitempty"`
// GitHubUsers contains names of individual users who can rerun the job
GitHubUsers []string `json:"github_users,omitempty"`
}

type ReporterConfig struct {
Expand Down
31 changes: 31 additions & 0 deletions prow/apis/prowjobs/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions prow/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -829,6 +829,9 @@ func validateJobBase(v JobBase, jobType prowapi.ProwJobType, podNamespace string
if v.Spec == nil || len(v.Spec.Containers) == 0 {
return nil // knative-build and jenkins jobs have no spec
}
if v.RerunPermissions != nil && v.RerunPermissions.AllowAnyone && (len(v.RerunPermissions.GitHubUsers) > 0 || len(v.RerunPermissions.GitHubTeams) > 0) {
return errors.New("allow anyone is set to true and permitted users or groups are specified")
}
return validateDecoration(v.Spec.Containers[0], v.DecorationConfig)
}

Expand Down
10 changes: 10 additions & 0 deletions prow/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -959,6 +959,16 @@ func TestValidateJobBase(t *testing.T) {
},
pass: true,
},
{
name: "invalid rerun_permissions",
base: JobBase{
RerunPermissions: &prowapi.RerunPermissions{
AllowAnyone: true,
GitHubUsers: []string{"user"},
},
},
pass: false,
},
}

for _, tc := range cases {
Expand Down
2 changes: 2 additions & 0 deletions prow/config/jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ type JobBase struct {
Annotations map[string]string `json:"annotations,omitempty"`
// ReporterConfig provides the option to configure reporting on job level
ReporterConfig *prowapi.ReporterConfig `json:"reporter_config,omitempty"`
// RerunPermissions specifies who can rerun the job
RerunPermissions *prowapi.RerunPermissions `json:"rerun_permissions,omitempty"`

UtilityConfig
}
Expand Down
3 changes: 2 additions & 1 deletion prow/pjutil/pjutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,8 @@ func specFromJobBase(jb config.JobBase) prowapi.ProwJobSpec {
BuildSpec: jb.BuildSpec,
PipelineRunSpec: jb.PipelineRunSpec,

ReporterConfig: jb.ReporterConfig,
ReporterConfig: jb.ReporterConfig,
RerunPermissions: jb.RerunPermissions,
}
}

Expand Down
27 changes: 27 additions & 0 deletions prow/pjutil/pjutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,8 @@ func TestCreateRefs(t *testing.T) {
}

func TestSpecFromJobBase(t *testing.T) {
permittedGroups := []int{1234, 5678}
permittedUsers := []string{"authorized_user", "another_authorized_user"}
testCases := []struct {
name string
jobBase config.JobBase
Expand Down Expand Up @@ -774,6 +776,31 @@ func TestSpecFromJobBase(t *testing.T) {
return nil
},
},
{
name: "Verify rerun permissions gets copied",
jobBase: config.JobBase{
RerunPermissions: &prowapi.RerunPermissions{
AllowAnyone: false,
GitHubTeams: permittedGroups,
GitHubUsers: permittedUsers,
},
},
verify: func(pj prowapi.ProwJobSpec) error {
if pj.RerunPermissions == nil {
return errors.New("Expected RerunPermissions to be non-nil")
}
if pj.RerunPermissions.AllowAnyone {
return errors.New("Expected RerunPermissions.AllowAnyone to be false")
}
if pj.RerunPermissions.GitHubTeams == nil {
return errors.New("Expected RerunPermissions.Groups to be non-nil")
}
if pj.RerunPermissions.GitHubUsers == nil {
return errors.New("Expected RerunPermissions.Users to be non-nil")
}
return nil
},
},
}

for _, tc := range testCases {
Expand Down

0 comments on commit b86afbd

Please sign in to comment.