Skip to content

Commit

Permalink
Improved code style
Browse files Browse the repository at this point in the history
  • Loading branch information
zc-devs committed Jan 5, 2024
1 parent e06a822 commit 86975ff
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
6 changes: 3 additions & 3 deletions pipeline/backend/kubernetes/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -393,12 +393,12 @@ func apparmorAnnotation(containerName string, scp *types.SecProfile) (*string, *
profilePath string
)

if scp.Type == "RuntimeDefault" {
if scp.Type == types.SecProfileTypeRuntimeDefault {
profileType = "runtime"
profilePath = "default"
}

if scp.Type == "Localhost" {
if scp.Type == types.SecProfileTypeLocalhost {
profileType = "localhost"
profilePath = scp.LocalhostProfile
}
Expand All @@ -407,7 +407,7 @@ func apparmorAnnotation(containerName string, scp *types.SecProfile) (*string, *
return nil, nil
}

key := "container.apparmor.security.beta.kubernetes.io/" + containerName
key := v1.AppArmorBetaContainerAnnotationKeyPrefix + containerName
value := profileType + "/" + profilePath
return &key, &value
}
Expand Down
11 changes: 9 additions & 2 deletions pipeline/backend/types/backend_kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ type SecurityContext struct {
}

type SecProfile struct {
Type string `json:"type,omitempty"`
LocalhostProfile string `json:"localhostProfile,omitempty"`
Type SecProfileType `json:"type,omitempty"`
LocalhostProfile string `json:"localhostProfile,omitempty"`
}

type SecProfileType string

const (
SecProfileTypeRuntimeDefault SecProfileType = "RuntimeDefault"
SecProfileTypeLocalhost SecProfileType = "Localhost"
)
4 changes: 2 additions & 2 deletions pipeline/frontend/yaml/compiler/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,13 +243,13 @@ func convertKubernetesBackendOptions(kubeOpt *yaml_types.KubernetesBackendOption
}
if kubeOpt.SecurityContext.SeccompProfile != nil {
securityContext.SeccompProfile = &backend_types.SecProfile{
Type: kubeOpt.SecurityContext.SeccompProfile.Type,
Type: backend_types.SecProfileType(kubeOpt.SecurityContext.SeccompProfile.Type),
LocalhostProfile: kubeOpt.SecurityContext.SeccompProfile.LocalhostProfile,
}
}
if kubeOpt.SecurityContext.ApparmorProfile != nil {
securityContext.ApparmorProfile = &backend_types.SecProfile{
Type: kubeOpt.SecurityContext.SeccompProfile.Type,
Type: backend_types.SecProfileType(kubeOpt.SecurityContext.SeccompProfile.Type),
LocalhostProfile: kubeOpt.SecurityContext.SeccompProfile.LocalhostProfile,
}
}
Expand Down

0 comments on commit 86975ff

Please sign in to comment.