idx int64 0 167k | question stringlengths 60 3.56k | target stringlengths 5 1.43k | len_question int64 21 889 | len_target int64 3 529 |
|---|---|---|---|---|
0 | func getAllDepTypes ( ) [ ] string { depTypes := make ( [ ] string , 0 , len ( cmds ) ) for depType := range cmds { depTypes = append ( depTypes , depType ) } sort . Strings ( depTypes ) return depTypes } | getAllDepTypes returns a sorted list of names of all dep type commands . | 60 | 16 |
1 | func getIoProgressReader ( label string , res * http . Response ) io . Reader { prefix := " " + label fmtBytesSize := 18 barSize := int64 ( 80 - len ( prefix ) - fmtBytesSize ) bar := ioprogress . DrawTextFormatBarForW ( barSize , os . Stderr ) fmtfunc := func ( progress , total int64 ) string { // Content-Length is se... | getIoProgressReader returns a reader that wraps the HTTP response body so it prints a pretty progress bar when reading data from it . | 217 | 27 |
2 | func ( f * removeOnClose ) Close ( ) error { if f == nil || f . File == nil { return nil } name := f . File . Name ( ) if err := f . File . Close ( ) ; err != nil { return err } if err := os . Remove ( name ) ; err != nil && ! os . IsNotExist ( err ) { return err } return nil } | Close closes the file and then removes it from disk . No error is returned if the file did not exist at the point of removal . | 85 | 27 |
3 | func getTmpROC ( s * imagestore . Store , path string ) ( * removeOnClose , error ) { h := sha512 . New ( ) h . Write ( [ ] byte ( path ) ) pathHash := s . HashToKey ( h ) tmp , err := s . TmpNamedFile ( pathHash ) if err != nil { return nil , errwrap . Wrap ( errors . New ( " " ) , err ) } // let's lock the file to av... | getTmpROC returns a removeOnClose instance wrapping a temporary file provided by the passed store . The actual file name is based on a hash of the passed path . | 243 | 35 |
4 | func getStage1Entrypoint ( cdir string , entrypoint string ) ( string , error ) { b , err := ioutil . ReadFile ( common . Stage1ManifestPath ( cdir ) ) if err != nil { return " " , errwrap . Wrap ( errors . New ( " " ) , err ) } s1m := schema . ImageManifest { } if err := json . Unmarshal ( b , & s1m ) ; err != nil { r... | getStage1Entrypoint retrieves the named entrypoint from the stage1 manifest for a given pod | 162 | 20 |
5 | func getStage1InterfaceVersion ( cdir string ) ( int , error ) { b , err := ioutil . ReadFile ( common . Stage1ManifestPath ( cdir ) ) if err != nil { return - 1 , errwrap . Wrap ( errors . New ( " " ) , err ) } s1m := schema . ImageManifest { } if err := json . Unmarshal ( b , & s1m ) ; err != nil { return - 1 , errwr... | getStage1InterfaceVersion retrieves the interface version from the stage1 manifest for a given pod | 198 | 19 |
6 | func ( e * podEnv ) loadNets ( ) ( [ ] activeNet , error ) { if e . netsLoadList . None ( ) { stderr . Printf ( " " ) return nil , nil } nets , err := e . newNetLoader ( ) . loadNets ( e . netsLoadList ) if err != nil { return nil , err } netSlice := make ( [ ] activeNet , 0 , len ( nets ) ) for _ , net := range nets {... | Loads nets specified by user both from a configurable user location and builtin from stage1 . User supplied network configs override what is built into stage1 . The order in which networks are applied to pods will be defined by their filenames . | 240 | 51 |
7 | func prepareApp ( p * stage1commontypes . Pod , ra * schema . RuntimeApp ) ( * preparedApp , error ) { pa := preparedApp { app : ra , env : ra . App . Environment , noNewPrivileges : getAppNoNewPrivileges ( ra . App . Isolators ) , } var err error // Determine numeric uid and gid u , g , err := ParseUserGroup ( p , ra ... | prepareApp sets up the internal runtime context for a specific app . | 617 | 14 |
8 | func computeAppResources ( isolators types . Isolators ) ( appResources , error ) { res := appResources { } var err error withIsolator := func ( name string , f func ( ) error ) error { ok , err := cgroup . IsIsolatorSupported ( name ) if err != nil { return errwrap . Wrapf ( " " + name , err ) } if ! ok { fmt . Fprint... | computeAppResources processes any isolators that manipulate cgroups . | 385 | 13 |
9 | func GetACIInfosWithKeyPrefix ( tx * sql . Tx , prefix string ) ( [ ] * ACIInfo , error ) { var aciinfos [ ] * ACIInfo rows , err := tx . Query ( " " , prefix ) if err != nil { return nil , err } defer rows . Close ( ) for rows . Next ( ) { aciinfo := & ACIInfo { } if err := aciinfoRowScan ( rows , aciinfo ) ; err != n... | GetAciInfosWithKeyPrefix returns all the ACIInfos with a blobkey starting with the given prefix . | 157 | 26 |
10 | func GetACIInfosWithName ( tx * sql . Tx , name string ) ( [ ] * ACIInfo , bool , error ) { var aciinfos [ ] * ACIInfo found := false rows , err := tx . Query ( " " , name ) if err != nil { return nil , false , err } defer rows . Close ( ) for rows . Next ( ) { found = true aciinfo := & ACIInfo { } if err := aciinfoRow... | GetAciInfosWithName returns all the ACIInfos for a given name . found will be false if no aciinfo exists . | 171 | 30 |
11 | func GetACIInfoWithBlobKey ( tx * sql . Tx , blobKey string ) ( * ACIInfo , bool , error ) { aciinfo := & ACIInfo { } found := false rows , err := tx . Query ( " " , blobKey ) if err != nil { return nil , false , err } defer rows . Close ( ) for rows . Next ( ) { found = true if err := aciinfoRowScan ( rows , aciinfo )... | GetAciInfosWithBlobKey returns the ACIInfo with the given blobKey . found will be false if no aciinfo exists . | 157 | 31 |
12 | func GetAllACIInfos ( tx * sql . Tx , sortfields [ ] string , ascending bool ) ( [ ] * ACIInfo , error ) { var aciinfos [ ] * ACIInfo query := " " if len ( sortfields ) > 0 { query += fmt . Sprintf ( " " , strings . Join ( sortfields , " " ) ) if ascending { query += " " } else { query += " " } } rows , err := tx . Que... | GetAllACIInfos returns all the ACIInfos sorted by optional sortfields and with ascending or descending order . | 207 | 25 |
13 | func WriteACIInfo ( tx * sql . Tx , aciinfo * ACIInfo ) error { // ql doesn't have an INSERT OR UPDATE function so // it's faster to remove and reinsert the row _ , err := tx . Exec ( " " , aciinfo . BlobKey ) if err != nil { return err } _ , err = tx . Exec ( " " , aciinfo . BlobKey , aciinfo . Name , aciinfo . Import... | WriteACIInfo adds or updates the provided aciinfo . | 144 | 13 |
14 | func StartCmd ( wdPath , name , kernelPath string , nds [ ] kvm . NetDescriber , cpu , mem int64 , debug bool ) [ ] string { var ( driverConfiguration = hypervisor . KvmHypervisor { Bin : " " , KernelParams : [ ] string { " " , " " , " " , " " , " " , " " , } , } ) driverConfiguration . InitKernelParams ( debug ) cmd :... | StartCmd takes path to stage1 name of the machine path to kernel network describers memory in megabytes and quantity of cpus and prepares command line to run QEMU process | 245 | 36 |
15 | func kvmNetArgs ( nds [ ] kvm . NetDescriber ) [ ] string { var qemuArgs [ ] string for _ , nd := range nds { qemuArgs = append ( qemuArgs , [ ] string { " " , " " } ... ) qemuNic := fmt . Sprintf ( " " , nd . IfName ( ) ) qemuArgs = append ( qemuArgs , [ ] string { " " , qemuNic } ... ) } return qemuArgs } | kvmNetArgs returns additional arguments that need to be passed to qemu to configure networks properly . Logic is based on network configuration extracted from Networking struct and essentially from activeNets that expose NetDescriber behavior | 117 | 44 |
16 | func ( hv * KvmHypervisor ) InitKernelParams ( isDebug bool ) { hv . KernelParams = append ( hv . KernelParams , [ ] string { " " , " " , " " , " " , " " } ... ) if isDebug { hv . KernelParams = append ( hv . KernelParams , [ ] string { " " , " " , " " , } ... ) } else { hv . KernelParams = append ( hv . KernelParams ,... | InitKernelParams sets debug and common parameters passed to the kernel | 184 | 14 |
17 | func ( f * dockerFetcher ) Hash ( u * url . URL ) ( string , error ) { ensureLogger ( f . Debug ) dockerURL , err := d2acommon . ParseDockerURL ( path . Join ( u . Host , u . Path ) ) if err != nil { return " " , fmt . Errorf ( `invalid docker URL %q; expected syntax is "docker://[REGISTRY_HOST[:REGISTRY_PORT]/]IMAGE_N... | Hash uses docker2aci to download the image and convert it to ACI then stores it in the store and returns the hash . | 140 | 26 |
18 | func registerPod ( root string , uuid * types . UUID , apps schema . AppList ) ( token string , rerr error ) { u := uuid . String ( ) var err error token , err = generateMDSToken ( ) if err != nil { rerr = errwrap . Wrap ( errors . New ( " " ) , err ) return } pmfPath := common . PodManifestPath ( root ) pmf , err := o... | registerPod registers pod with metadata service . Returns authentication token to be passed in the URL | 386 | 17 |
19 | func unregisterPod ( root string , uuid * types . UUID ) error { _ , err := os . Stat ( filepath . Join ( root , mdsRegisteredFile ) ) switch { case err == nil : pth := path . Join ( " " , uuid . String ( ) ) return httpRequest ( " " , pth , nil ) case os . IsNotExist ( err ) : return nil default : return err } } | unregisterPod unregisters pod with the metadata service . | 94 | 12 |
20 | func CheckMdsAvailability ( ) error { if conn , err := net . Dial ( " " , common . MetadataServiceRegSock ) ; err != nil { return errUnreachable } else { conn . Close ( ) return nil } } | CheckMdsAvailability checks whether a local metadata service can be reached . | 52 | 14 |
21 | func ( ni * NetInfo ) MergeCNIResult ( result types . Result ) { ni . IP = result . IP4 . IP . IP ni . Mask = net . IP ( result . IP4 . IP . Mask ) ni . HostIP = result . IP4 . Gateway ni . IP4 = result . IP4 ni . DNS = result . DNS } | MergeCNIResult will incorporate the result of a CNI plugin s execution | 76 | 17 |
22 | func Add ( name string , fn commandFn ) Entrypoint { if _ , ok := commands [ name ] ; ok { panic ( fmt . Errorf ( " " , name ) ) } commands [ name ] = fn return Entrypoint ( name ) } | Add adds a new multicall command . name is the command name and fn is the function that will be executed for the specified command . It returns the related Entrypoint . Packages adding new multicall commands should call Add in their init function . | 53 | 49 |
23 | func addStage1ImageFlags ( flags * pflag . FlagSet ) { for _ , data := range stage1FlagsData { wrapper := & stage1ImageLocationFlag { loc : & overriddenStage1Location , kind : data . kind , } flags . Var ( wrapper , data . flag , data . help ) } } | addStage1ImageFlags adds flags for specifying custom stage1 image | 68 | 13 |
24 | func HasChrootCapability ( ) bool { // Checking the capabilities should be enough, but in case there're // problem retrieving them, fallback checking for the effective uid // (hoping it hasn't dropped its CAP_SYS_CHROOT). caps , err := capability . NewPid ( 0 ) if err == nil { return caps . Get ( capability . EFFECTIVE... | HasChrootCapability checks if the current process has the CAP_SYS_CHROOT capability | 108 | 21 |
25 | func LookupGidFromFile ( groupName , groupFile string ) ( gid int , err error ) { groups , err := parseGroupFile ( groupFile ) if err != nil { return - 1 , errwrap . Wrap ( fmt . Errorf ( " " , groupFile ) , err ) } group , ok := groups [ groupName ] if ! ok { return - 1 , fmt . Errorf ( " " , groupName ) } return grou... | LookupGid reads the group file specified by groupFile and returns the gid of the group specified by groupName . | 101 | 25 |
26 | func TryExclusiveKeyLock ( lockDir string , key string ) ( * KeyLock , error ) { return createAndLock ( lockDir , key , keyLockExclusive | keyLockNonBlocking ) } | TryExclusiveLock takes an exclusive lock on the key without blocking . lockDir is the directory where the lock file will be created . It will return ErrLocked if any lock is already held . | 44 | 40 |
27 | func ExclusiveKeyLock ( lockDir string , key string ) ( * KeyLock , error ) { return createAndLock ( lockDir , key , keyLockExclusive ) } | ExclusiveLock takes an exclusive lock on a key . lockDir is the directory where the lock file will be created . It will block if an exclusive lock is already held on the key . | 36 | 38 |
28 | func ( l * KeyLock ) Unlock ( ) error { err := l . keyLock . Unlock ( ) if err != nil { return err } return nil } | Unlock unlocks the key lock . | 33 | 7 |
29 | func CleanKeyLocks ( lockDir string ) error { f , err := os . Open ( lockDir ) if err != nil { return errwrap . Wrap ( errors . New ( " " ) , err ) } defer f . Close ( ) files , err := f . Readdir ( 0 ) if err != nil { return errwrap . Wrap ( errors . New ( " " ) , err ) } for _ , f := range files { filename := filepat... | CleanKeyLocks remove lock files from the lockDir . For every key it tries to take an Exclusive lock on it and skip it if it fails with ErrLocked | 192 | 34 |
30 | func ( m * Manager ) GetPubKeyLocations ( prefix string ) ( [ ] string , error ) { ensureLogger ( m . Debug ) if prefix == " " { return nil , fmt . Errorf ( " " ) } kls , err := m . metaDiscoverPubKeyLocations ( prefix ) if err != nil { return nil , errwrap . Wrap ( errors . New ( " " ) , err ) } if len ( kls ) == 0 { ... | GetPubKeyLocations discovers locations at prefix | 118 | 9 |
31 | func ( m * Manager ) AddKeys ( pkls [ ] string , prefix string , accept AcceptOption ) error { ensureLogger ( m . Debug ) if m . Ks == nil { return fmt . Errorf ( " " ) } for _ , pkl := range pkls { u , err := url . Parse ( pkl ) if err != nil { return err } pk , err := m . getPubKey ( u ) if err != nil { return errwra... | AddKeys adds the keys listed in pkls at prefix | 486 | 12 |
32 | func ( m * Manager ) metaDiscoverPubKeyLocations ( prefix string ) ( [ ] string , error ) { app , err := discovery . NewAppFromString ( prefix ) if err != nil { return nil , err } hostHeaders := config . ResolveAuthPerHost ( m . AuthPerHost ) insecure := discovery . InsecureNone if m . InsecureAllowHTTP { insecure = in... | metaDiscoverPubKeyLocations discovers the locations of public keys through ACDiscovery by applying prefix as an ACApp | 182 | 23 |
33 | func downloadKey ( u * url . URL , skipTLSCheck bool ) ( * os . File , error ) { tf , err := ioutil . TempFile ( " " , " " ) if err != nil { return nil , errwrap . Wrap ( errors . New ( " " ) , err ) } os . Remove ( tf . Name ( ) ) // no need to keep the tempfile around defer func ( ) { if tf != nil { tf . Close ( ) } ... | downloadKey retrieves the file storing it in a deleted tempfile | 318 | 13 |
34 | func displayKey ( prefix , location string , key * os . File ) error { defer key . Seek ( 0 , os . SEEK_SET ) kr , err := openpgp . ReadArmoredKeyRing ( key ) if err != nil { return errwrap . Wrap ( errors . New ( " " ) , err ) } log . Printf ( " \n " , prefix , location ) for _ , k := range kr { stdout . Printf ( " " ... | displayKey shows the key summary | 176 | 6 |
35 | func reviewKey ( ) ( bool , error ) { in := bufio . NewReader ( os . Stdin ) for { stdout . Printf ( " " ) input , err := in . ReadString ( '\n' ) if err != nil { return false , errwrap . Wrap ( errors . New ( " " ) , err ) } switch input { case " \n " : return true , nil case " \n " : return false , nil default : stdo... | reviewKey asks the user to accept the key | 110 | 9 |
36 | func setupTapDevice ( podID types . UUID ) ( netlink . Link , error ) { // network device names are limited to 16 characters // the suffix %d will be replaced by the kernel with a suitable number nameTemplate := fmt . Sprintf ( " " , podID . String ( ) [ 0 : 4 ] ) ifName , err := tuntap . CreatePersistentIface ( nameTe... | setupTapDevice creates persistent tap device and returns a newly created netlink . Link structure | 203 | 17 |
37 | func setupMacVTapDevice ( podID types . UUID , config MacVTapNetConf , interfaceNumber int ) ( netlink . Link , error ) { master , err := netlink . LinkByName ( config . Master ) if err != nil { return nil , errwrap . Wrap ( fmt . Errorf ( " " , config . Master ) , err ) } var mode netlink . MacvlanMode switch config .... | setupTapDevice creates persistent macvtap device and returns a newly created netlink . Link structure using part of pod hash and interface number in interface name | 577 | 30 |
38 | func ( n * Networking ) kvmTeardown ( ) { if err := n . teardownForwarding ( ) ; err != nil { stderr . PrintE ( " " , err ) } n . teardownKvmNets ( ) } | kvmTeardown network teardown for kvm flavor based pods similar to Networking . Teardown but without host namespaces | 57 | 28 |
39 | func ( f * fileFetcher ) Hash ( aciPath string , a * asc ) ( string , error ) { ensureLogger ( f . Debug ) absPath , err := filepath . Abs ( aciPath ) if err != nil { return " " , errwrap . Wrap ( fmt . Errorf ( " " , aciPath ) , err ) } aciPath = absPath aciFile , err := f . getFile ( aciPath , a ) if err != nil { ret... | Hash opens a file optionally verifies it against passed asc stores it in the store and returns the hash . | 167 | 21 |
40 | func ( f * fileFetcher ) getVerifiedFile ( aciPath string , a * asc ) ( * os . File , error ) { var aciFile * os . File // closed on error var errClose error // error signaling to close aciFile f . maybeOverrideAsc ( aciPath , a ) ascFile , err := a . Get ( ) if err != nil { return nil , errwrap . Wrap ( errors . New (... | fetch opens and verifies the ACI . | 266 | 10 |
41 | func NewLoggingMounter ( m Mounter , um Unmounter , logf func ( string , ... interface { } ) ) MountUnmounter { return & loggingMounter { m , um , logf } } | NewLoggingMounter returns a MountUnmounter that logs mount events using the given logger func . | 47 | 21 |
42 | func Extend ( description string ) error { connection := tpmclient . New ( " " , timeout ) err := connection . Extend ( 15 , 0x1000 , nil , description ) return err } | Extend extends the TPM log with the provided string . Returns any error . | 40 | 16 |
43 | func Stage1RootfsPath ( root string ) string { return filepath . Join ( Stage1ImagePath ( root ) , aci . RootfsDir ) } | Stage1RootfsPath returns the path to the stage1 rootfs | 34 | 14 |
44 | func Stage1ManifestPath ( root string ) string { return filepath . Join ( Stage1ImagePath ( root ) , aci . ManifestFile ) } | Stage1ManifestPath returns the path to the stage1 s manifest file inside the expanded ACI . | 33 | 21 |
45 | func AppStatusPath ( root , appName string ) string { return filepath . Join ( AppsStatusesPath ( root ) , appName ) } | AppStatusPath returns the path of the status file of an app . | 31 | 14 |
46 | func AppStatusPathFromStage1Rootfs ( rootfs , appName string ) string { return filepath . Join ( AppsStatusesPathFromStage1Rootfs ( rootfs ) , appName ) } | AppStatusPathFromStage1Rootfs returns the path of the status file of an app . It receives the stage1 rootfs as parameter instead of the pod root . | 43 | 34 |
47 | func AppPath ( root string , appName types . ACName ) string { return filepath . Join ( AppsPath ( root ) , appName . String ( ) ) } | AppPath returns the path to an app s rootfs . | 36 | 12 |
48 | func AppRootfsPath ( root string , appName types . ACName ) string { return filepath . Join ( AppPath ( root , appName ) , aci . RootfsDir ) } | AppRootfsPath returns the path to an app s rootfs . | 41 | 14 |
49 | func RelAppPath ( appName types . ACName ) string { return filepath . Join ( stage2Dir , appName . String ( ) ) } | RelAppPath returns the path of an app relative to the stage1 chroot . | 32 | 17 |
50 | func RelAppRootfsPath ( appName types . ACName ) string { return filepath . Join ( RelAppPath ( appName ) , aci . RootfsDir ) } | RelAppRootfsPath returns the path of an app s rootfs relative to the stage1 chroot . | 38 | 22 |
51 | func ImageManifestPath ( root string , appName types . ACName ) string { return filepath . Join ( AppPath ( root , appName ) , aci . ManifestFile ) } | ImageManifestPath returns the path to the app s manifest file of a pod . | 40 | 17 |
52 | func AppInfoPath ( root string , appName types . ACName ) string { return filepath . Join ( AppsInfoPath ( root ) , appName . String ( ) ) } | AppInfoPath returns the path to the app s appsinfo directory of a pod . | 38 | 17 |
53 | func AppTreeStoreIDPath ( root string , appName types . ACName ) string { return filepath . Join ( AppInfoPath ( root , appName ) , AppTreeStoreIDFilename ) } | AppTreeStoreIDPath returns the path to the app s treeStoreID file of a pod . | 42 | 20 |
54 | func AppImageManifestPath ( root string , appName types . ACName ) string { return filepath . Join ( AppInfoPath ( root , appName ) , aci . ManifestFile ) } | AppImageManifestPath returns the path to the app s ImageManifest file | 42 | 16 |
55 | func CreateSharedVolumesPath ( root string ) ( string , error ) { sharedVolPath := SharedVolumesPath ( root ) if err := os . MkdirAll ( sharedVolPath , SharedVolumePerm ) ; err != nil { return " " , errwrap . Wrap ( errors . New ( " " ) , err ) } // In case it already existed and we didn't make it, ensure permissions a... | CreateSharedVolumesPath ensures the sharedVolumePath for the pod root passed in exists . It returns the shared volume path or an error . | 150 | 29 |
56 | func MetadataServicePublicURL ( ip net . IP , token string ) string { return fmt . Sprintf ( " " , ip , MetadataServicePort , token ) } | MetadataServicePublicURL returns the public URL used to host the metadata service | 36 | 15 |
57 | func LookupPath ( bin string , paths string ) ( string , error ) { pathsArr := filepath . SplitList ( paths ) for _ , path := range pathsArr { binPath := filepath . Join ( path , bin ) binAbsPath , err := filepath . Abs ( binPath ) if err != nil { return " " , fmt . Errorf ( " " , binPath ) } if fileutil . IsExecutable... | LookupPath search for bin in paths . If found it returns its absolute path if not an error | 124 | 20 |
58 | func SystemdVersion ( systemdBinaryPath string ) ( int , error ) { versionBytes , err := exec . Command ( systemdBinaryPath , " " ) . CombinedOutput ( ) if err != nil { return - 1 , errwrap . Wrap ( fmt . Errorf ( " " , systemdBinaryPath ) , err ) } versionStr := strings . SplitN ( string ( versionBytes ) , " \n " , 2 ... | SystemdVersion parses and returns the version of a given systemd binary | 146 | 14 |
59 | func SupportsOverlay ( ) error { // ignore exec.Command error, modprobe may not be present on the system, // or the kernel module will fail to load. // we'll find out by reading the side effect in /proc/filesystems _ = exec . Command ( " " , " " ) . Run ( ) f , err := os . Open ( " " ) if err != nil { // don't use errw... | SupportsOverlay returns whether the operating system generally supports OverlayFS returning an instance of ErrOverlayUnsupported which encodes the reason . It is sufficient to check for nil if the reason is not of interest . | 173 | 44 |
60 | func RemoveEmptyLines ( str string ) [ ] string { lines := make ( [ ] string , 0 ) for _ , v := range strings . Split ( str , " \n " ) { if len ( v ) > 0 { lines = append ( lines , v ) } } return lines } | RemoveEmptyLines removes empty lines from the given string and breaks it up into a list of strings at newline characters | 62 | 24 |
61 | func GetExitStatus ( err error ) ( int , error ) { if err == nil { return 0 , nil } if exiterr , ok := err . ( * exec . ExitError ) ; ok { // the program has exited with an exit code != 0 if status , ok := exiterr . Sys ( ) . ( syscall . WaitStatus ) ; ok { return status . ExitStatus ( ) , nil } } return - 1 , err } | GetExitStatus converts an error to an exit status . If it wasn t an exit status ! = 0 it returns the same error that it was called with | 96 | 31 |
62 | func ImageNameToAppName ( name types . ACIdentifier ) ( * types . ACName , error ) { parts := strings . Split ( name . String ( ) , " " ) last := parts [ len ( parts ) - 1 ] sn , err := types . SanitizeACName ( last ) if err != nil { return nil , err } return types . MustACName ( sn ) , nil } | ImageNameToAppName converts the full name of image to an app name without special characters - we use it as a default app name when specyfing it is optional | 86 | 34 |
63 | func GetNetworkDescriptions ( n * networking . Networking ) [ ] NetDescriber { var nds [ ] NetDescriber for _ , an := range n . GetActiveNetworks ( ) { nds = append ( nds , an ) } return nds } | GetNetworkDescriptions converts activeNets to netDescribers | 58 | 14 |
64 | func GetKVMNetArgs ( nds [ ] NetDescriber ) ( [ ] string , error ) { var lkvmArgs [ ] string for _ , nd := range nds { lkvmArgs = append ( lkvmArgs , " " ) lkvmArg := fmt . Sprintf ( " " , nd . IfName ( ) , nd . Gateway ( ) , nd . GuestIP ( ) ) lkvmArgs = append ( lkvmArgs , lkvmArg ) } return lkvmArgs , nil } | GetKVMNetArgs returns additional arguments that need to be passed to lkvm tool to configure networks properly . Logic is based on Network configuration extracted from Networking struct and essentially from activeNets that expose netDescriber behavior | 118 | 46 |
65 | func generateMacAddress ( ) ( net . HardwareAddr , error ) { mac := [ ] byte { 2 , // locally administered unicast 0x65 , 0x02 , // OUI (randomly chosen by jell) 0 , 0 , 0 , // bytes to randomly overwrite } _ , err := rand . Read ( mac [ 3 : 6 ] ) if err != nil { return nil , errwrap . Wrap ( errors . New ( " " ) , err... | generateMacAddress returns net . HardwareAddr filled with fixed 3 byte prefix complemented by 3 random bytes . | 104 | 23 |
66 | func replacePlaceholders ( str string , kv ... string ) string { for ph , value := range toMap ( kv ... ) { str = strings . Replace ( str , " " + ph + " " , value , - 1 ) } return str } | replacePlaceholders replaces placeholders with values in kv in initial str . Placeholders are in form of !!!FOO!!! but those passed here should be without exclamation marks . | 54 | 37 |
67 | func standardFlags ( cmd string ) ( * flag . FlagSet , * string ) { f := flag . NewFlagSet ( appName ( ) + " " + cmd , flag . ExitOnError ) target := f . String ( " " , " " , " " ) return f , target } | standardFlags returns a new flag set with target flag already set up | 62 | 13 |
68 | func ( e * podEnv ) netPluginAdd ( n * activeNet , netns string ) error { output , err := e . execNetPlugin ( " " , n , netns ) if err != nil { return pluginErr ( err , output ) } pr := cnitypes . Result { } if err = json . Unmarshal ( output , & pr ) ; err != nil { err = errwrap . Wrap ( fmt . Errorf ( " " , string ( ... | Executes a given network plugin . If successful mutates n . runtime with the runtime information | 181 | 18 |
69 | func copyPod ( pod * v1alpha . Pod ) * v1alpha . Pod { p := & v1alpha . Pod { Id : pod . Id , Manifest : pod . Manifest , Annotations : pod . Annotations , } for _ , app := range pod . Apps { p . Apps = append ( p . Apps , & v1alpha . App { Name : app . Name , Image : app . Image , Annotations : app . Annotations , } )... | copyPod copies the immutable information of the pod into the new pod . | 98 | 14 |
70 | func copyImage ( img * v1alpha . Image ) * v1alpha . Image { return & v1alpha . Image { BaseFormat : img . BaseFormat , Id : img . Id , Name : img . Name , Version : img . Version , ImportTimestamp : img . ImportTimestamp , Manifest : img . Manifest , Size : img . Size , Annotations : img . Annotations , Labels : img .... | copyImage copies the image object to avoid modification on the original one . | 91 | 14 |
71 | func ( s * v1AlphaAPIServer ) GetInfo ( context . Context , * v1alpha . GetInfoRequest ) ( * v1alpha . GetInfoResponse , error ) { return & v1alpha . GetInfoResponse { Info : & v1alpha . Info { RktVersion : version . Version , AppcVersion : schema . AppContainerVersion . String ( ) , ApiVersion : supportedAPIVersion , ... | GetInfo returns the information about the rkt appc api server version . | 181 | 15 |
72 | func containsAllKeyValues ( actualKVs [ ] * v1alpha . KeyValue , requiredKVs [ ] * v1alpha . KeyValue ) bool { for _ , requiredKV := range requiredKVs { actualValue , ok := findInKeyValues ( actualKVs , requiredKV . Key ) if ! ok || actualValue != requiredKV . Value { return false } } return true } | containsAllKeyValues returns true if the actualKVs contains all of the key - value pairs listed in requiredKVs otherwise it returns false . | 86 | 30 |
73 | func satisfiesPodFilter ( pod v1alpha . Pod , filter v1alpha . PodFilter ) bool { // Filter according to the ID. if len ( filter . Ids ) > 0 { s := set . NewString ( filter . Ids ... ) if ! s . Has ( pod . Id ) { return false } } // Filter according to the state. if len ( filter . States ) > 0 { foundState := false for... | satisfiesPodFilter returns true if the pod satisfies the filter . The pod filter must not be nil . | 492 | 22 |
74 | func satisfiesAnyPodFilters ( pod * v1alpha . Pod , filters [ ] * v1alpha . PodFilter ) bool { // No filters, return true directly. if len ( filters ) == 0 { return true } for _ , filter := range filters { if satisfiesPodFilter ( * pod , * filter ) { return true } } return false } | satisfiesAnyPodFilters returns true if any of the filter conditions is satisfied by the pod or there s no filters . | 74 | 26 |
75 | func getApplist ( manifest * schema . PodManifest ) [ ] * v1alpha . App { var apps [ ] * v1alpha . App for _ , app := range manifest . Apps { img := & v1alpha . Image { BaseFormat : & v1alpha . ImageFormat { // Only support appc image now. If it's a docker image, then it // will be transformed to appc before storing in... | getApplist returns a list of apps in the pod . | 224 | 12 |
76 | func getNetworks ( p * pkgPod . Pod ) [ ] * v1alpha . Network { var networks [ ] * v1alpha . Network for _ , n := range p . Nets { networks = append ( networks , & v1alpha . Network { Name : n . NetName , // There will be IPv6 support soon so distinguish between v4 and v6 Ipv4 : n . IP . String ( ) , } ) } return netwo... | getNetworks returns the list of the info of the network that the pod belongs to . | 97 | 18 |
77 | func fillStaticAppInfo ( store * imagestore . Store , pod * pkgPod . Pod , v1pod * v1alpha . Pod ) error { var errlist [ ] error // Fill static app image info. for _ , app := range v1pod . Apps { // Fill app's image info. app . Image = & v1alpha . Image { BaseFormat : & v1alpha . ImageFormat { // Only support appc imag... | fillStaticAppInfo will modify the v1pod in place with the information retrieved with pod . Today these information are static and will not change during the pod s lifecycle . | 305 | 35 |
78 | func ( s * v1AlphaAPIServer ) getBasicPod ( p * pkgPod . Pod ) * v1alpha . Pod { mtime , mtimeErr := getPodManifestModTime ( p ) if mtimeErr != nil { stderr . PrintE ( fmt . Sprintf ( " " , p . UUID ) , mtimeErr ) } // Couldn't use pod.uuid directly as it's a pointer. itemValue , found := s . podCache . Get ( p . UUID ... | getBasicPod returns v1alpha . Pod with basic pod information . | 294 | 14 |
79 | func aciInfoToV1AlphaAPIImage ( store * imagestore . Store , aciInfo * imagestore . ACIInfo ) ( * v1alpha . Image , error ) { manifest , err := store . GetImageManifestJSON ( aciInfo . BlobKey ) if err != nil { stderr . PrintE ( " " , err ) return nil , err } var im schema . ImageManifest if err = json . Unmarshal ( ma... | aciInfoToV1AlphaAPIImage takes an aciInfo object and construct the v1alpha . Image object . | 325 | 24 |
80 | func satisfiesImageFilter ( image v1alpha . Image , filter v1alpha . ImageFilter ) bool { // Filter according to the IDs. if len ( filter . Ids ) > 0 { s := set . NewString ( filter . Ids ... ) if ! s . Has ( image . Id ) { return false } } // Filter according to the image full names. if len ( filter . FullNames ) > 0 ... | satisfiesImageFilter returns true if the image satisfies the filter . The image filter must not be nil . | 421 | 22 |
81 | func satisfiesAnyImageFilters ( image * v1alpha . Image , filters [ ] * v1alpha . ImageFilter ) bool { // No filters, return true directly. if len ( filters ) == 0 { return true } for _ , filter := range filters { if satisfiesImageFilter ( * image , * filter ) { return true } } return false } | satisfiesAnyImageFilters returns true if any of the filter conditions is satisfied by the image or there s no filters . | 74 | 26 |
82 | func runAPIService ( cmd * cobra . Command , args [ ] string ) ( exit int ) { // Set up the signal handler here so we can make sure the // signals are caught after print the starting message. signal . Notify ( exitCh , syscall . SIGINT , syscall . SIGTERM ) stderr . Print ( " " ) listeners , err := openAPISockets ( ) i... | Open one or more listening sockets then start the gRPC server | 263 | 13 |
83 | func ( uw * UnitWriter ) WriteUnit ( path string , errmsg string , opts ... * unit . UnitOption ) { if uw . err != nil { return } file , err := os . OpenFile ( path , os . O_WRONLY | os . O_CREATE | os . O_TRUNC , 0644 ) if err != nil { uw . err = errwrap . Wrap ( errors . New ( errmsg ) , err ) return } defer file . C... | WriteUnit writes a systemd unit in the given path with the given unit options if no previous error occurred . | 208 | 21 |
84 | func ( uw * UnitWriter ) writeShutdownService ( exec string , opts ... * unit . UnitOption ) { if uw . err != nil { return } flavor , systemdVersion , err := GetFlavor ( uw . p ) if err != nil { uw . err = errwrap . Wrap ( errors . New ( " " ) , err ) return } opts = append ( opts , [ ] * unit . UnitOption { // The def... | writeShutdownService writes a shutdown . service unit with the given unit options if no previous error occurred . exec specifies how systemctl should be invoked i . e . ExecStart or ExecStop . | 438 | 39 |
85 | func ( uw * UnitWriter ) Activate ( unit , wantPath string ) { if uw . err != nil { return } if err := os . Symlink ( path . Join ( " " , unit ) , wantPath ) ; err != nil && ! os . IsExist ( err ) { uw . err = errwrap . Wrap ( errors . New ( " " ) , err ) } } | Activate actives the given unit in the given wantPath . | 86 | 13 |
86 | func ( uw * UnitWriter ) AppUnit ( ra * schema . RuntimeApp , binPath string , opts ... * unit . UnitOption ) { if uw . err != nil { return } if len ( ra . App . Exec ) == 0 { uw . err = fmt . Errorf ( `image %q has an empty "exec" (try --exec=BINARY)` , uw . p . AppNameToImageName ( ra . Name ) ) return } pa , err := ... | AppUnit sets up the main systemd service unit for the application . | 599 | 13 |
87 | func ( uw * UnitWriter ) AppReaperUnit ( appName types . ACName , binPath string , opts ... * unit . UnitOption ) { if uw . err != nil { return } opts = append ( opts , [ ] * unit . UnitOption { unit . NewUnitOption ( " " , " " , fmt . Sprintf ( " " , appName ) ) , unit . NewUnitOption ( " " , " " , " " ) , unit . NewU... | AppReaperUnit writes an app reaper service unit for the given app in the given path using the given unit options . | 301 | 25 |
88 | func ( uw * UnitWriter ) AppSocketUnit ( appName types . ACName , binPath string , streamName string , opts ... * unit . UnitOption ) { opts = append ( opts , [ ] * unit . UnitOption { unit . NewUnitOption ( " " , " " , fmt . Sprintf ( " " , streamName , appName ) ) , unit . NewUnitOption ( " " , " " , " " ) , unit . N... | AppSocketUnits writes a stream socket - unit for the given app in the given path . | 321 | 19 |
89 | func appendOptionsList ( opts [ ] * unit . UnitOption , section , property , prefix string , vals ... string ) [ ] * unit . UnitOption { for _ , v := range vals { opts = append ( opts , unit . NewUnitOption ( section , property , fmt . Sprintf ( " " , prefix , v ) ) ) } return opts } | appendOptionsList updates an existing unit options list appending an array of new properties one entry at a time . This is the preferred method to avoid hitting line length limits in unit files . Target property must support multi - line entries . | 81 | 46 |
90 | func AppsForPod ( uuid , dataDir string , appName string ) ( [ ] * v1 . App , error ) { p , err := pkgPod . PodFromUUIDString ( dataDir , uuid ) if err != nil { return nil , err } defer p . Close ( ) return appsForPod ( p , appName , appStateInMutablePod ) } | AppsForPod returns the apps of the pod with the given uuid in the given data directory . If appName is non - empty then only the app with the given name will be returned . | 82 | 39 |
91 | func newApp ( ra * schema . RuntimeApp , podManifest * schema . PodManifest , pod * pkgPod . Pod , appState appStateFunc ) ( * v1 . App , error ) { app := & v1 . App { Name : ra . Name . String ( ) , ImageID : ra . Image . ID . String ( ) , UserAnnotations : ra . App . UserAnnotations , UserLabels : ra . App . UserLabe... | newApp constructs the App object with the runtime app and pod manifest . | 373 | 14 |
92 | func appStateInImmutablePod ( app * v1 . App , pod * pkgPod . Pod ) error { app . State = appStateFromPod ( pod ) t , err := pod . CreationTime ( ) if err != nil { return err } createdAt := t . UnixNano ( ) app . CreatedAt = & createdAt code , err := pod . AppExitCode ( app . Name ) if err == nil { // there is an exit ... | appStateInImmutablePod infers most App state from the Pod itself since all apps are created and destroyed with the Pod | 237 | 25 |
93 | func ( p * Pod ) SaveRuntime ( ) error { path := filepath . Join ( p . Root , RuntimeConfigPath ) buf , err := json . Marshal ( p . RuntimePod ) if err != nil { return err } return ioutil . WriteFile ( path , buf , 0644 ) } | SaveRuntime persists just the runtime state . This should be called when the pod is started . | 64 | 18 |
94 | func LoadPodManifest ( root string ) ( * schema . PodManifest , error ) { buf , err := ioutil . ReadFile ( common . PodManifestPath ( root ) ) if err != nil { return nil , errwrap . Wrap ( errors . New ( " " ) , err ) } pm := & schema . PodManifest { } if err := json . Unmarshal ( buf , pm ) ; err != nil { return nil ,... | LoadPodManifest loads a Pod Manifest . | 118 | 9 |
95 | func ( f * Fetcher ) FetchImages ( al * apps . Apps ) error { return al . Walk ( func ( app * apps . App ) error { d , err := DistFromImageString ( app . Image ) if err != nil { return err } h , err := f . FetchImage ( d , app . Image , app . Asc ) if err != nil { return err } app . ImageID = * h return nil } ) } | FetchImages uses FetchImage to attain a list of image hashes | 95 | 14 |
96 | func ( f * Fetcher ) FetchImage ( d dist . Distribution , image , ascPath string ) ( * types . Hash , error ) { ensureLogger ( f . Debug ) db := & distBundle { dist : d , image : image , } a := f . getAsc ( ascPath ) hash , err := f . fetchSingleImage ( db , a ) if err != nil { return nil , err } if f . WithDeps { err ... | FetchImage will take an image as either a path a URL or a name string and import it into the store if found . If ascPath is not it must exist as a local file and will be used as the signature file for verification unless verification is disabled . If f . WithDeps is true also image dependencies are fetched . | 260 | 68 |
97 | func ( f * Fetcher ) fetchImageDeps ( hash string ) error { imgsl := list . New ( ) seen := map [ string ] dist . Distribution { } f . addImageDeps ( hash , imgsl , seen ) for el := imgsl . Front ( ) ; el != nil ; el = el . Next ( ) { a := & asc { } d := el . Value . ( * dist . Appc ) str := d . String ( ) db := & dist... | fetchImageDeps will recursively fetch all the image dependencies | 154 | 14 |
98 | func New ( out io . Writer , prefix string , debug bool ) * Logger { l := & Logger { debug : debug , Logger : log . New ( out , prefix , 0 ) , } l . SetFlags ( 0 ) return l } | New creates a new Logger with no Log flags set . | 53 | 12 |
99 | func ( l * Logger ) Error ( e error ) { l . Print ( l . formatErr ( e , " " ) ) } | Error is a convenience function for printing errors without a message . | 30 | 12 |
End of preview. Expand in Data Studio
- Downloads last month
- 5